Results 1 to 11 of 11

Thread: How to bind sales header model to collection of sales Footer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    How to bind sales header model to collection of sales Footer

    problem
    How to bind sales header model to collection of sales Footer on SalesOrder controller using ASP.NET core 2.1?
    I work on project have Sales Order form this form contain to :

    salesHeader model

    salesFooter model

    so that i already have model Sales Header have navigation property to Sales Footer as following

    SalesHeader Model

    public int SalesOrderNo { get; set; }
    public int SalesYear { get; set; }
    public ICollection<SalesFooter> SalesFooters { get; set; }


    SalesFooter Model
    public int SalesOrderNo { get; set; }
    public int Quantity { get; set; }
    public int UnitPrice { get; set; }



    How to get collection of sales footer on :

    on Edit action of sales Order controller how to get collection of sales footer ?

    on Edit view(get) sales Order controller how to get collection of sales footer ?

    What I have tried:

    Repository

    public T GetById(int Id)
    {
    return dbSet.Find(Id);
    }
    public class SalesOrderController : Controller
    {
    private readonly IrepositoryTab<SalesHeader> _repositoryHeader;
    public SalesOrderController(IrepositoryTab<SalesHeader> SalesHeader, IrepositoryTab<SalesFooter> SalesFooter)
    {
    this._repositoryHeader = SalesHeader;
    this._repositoryFooter = SalesFooter;

    }

    //get
    //Edit Action of sales Order Controller

    public IActionResult Edit(int? id)
    {

    var SalesHeader = _repositoryHeader.GetById(id);
    //How to bind with sales footer
    return View();

    }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: How to bind sales header model to collection of sales Footer

    Reading unformatted code is rather unpleasant. Please format all code snippets appropriately. With 44 posts now, I would have expected that you'd have seen that done a number
    Quote Originally Posted by engbarbary View Post
    problem
    How to bind sales header model to collection of sales Footer on SalesOrder controller using ASP.NET core 2.1?
    I work on project have Sales Order form this form contain to :

    salesHeader model

    salesFooter model

    so that i already have model Sales Header have navigation property to Sales Footer as following

    SalesHeader Model

    csharp Code:
    1. public int SalesOrderNo { get; set; }
    2. public int SalesYear { get; set; }
    3. public ICollection<SalesFooter> SalesFooters { get; set; }


    SalesFooter Model
    csharp Code:
    1. public int SalesOrderNo { get; set; }  
    2. public int Quantity { get; set; }  
    3. public int UnitPrice { get; set; }



    How to get collection of sales footer on :

    on Edit action of sales Order controller how to get collection of sales footer ?

    on Edit view(get) sales Order controller how to get collection of sales footer ?

    What I have tried:

    Repository

    csharp Code:
    1. public T GetById(int Id)  
    2.         {  
    3.             return dbSet.Find(Id);  
    4.         }  
    5. public class SalesOrderController : Controller  
    6.     {  
    7.         private readonly IrepositoryTab<SalesHeader> _repositoryHeader;  
    8.         public  SalesOrderController(IrepositoryTab<SalesHeader> SalesHeader, IrepositoryTab<SalesFooter> SalesFooter)  
    9.         {  
    10.             this._repositoryHeader = SalesHeader;  
    11.             this._repositoryFooter = SalesFooter;  
    12.  
    13.         }  
    14.  
    15. //get  
    16. //Edit Action of sales Order Controller  
    17.  
    18. public IActionResult Edit(int? id)  
    19.        {  
    20.  
    21.            var SalesHeader = _repositoryHeader.GetById(id);  
    22.           //How to bind with sales footer  
    23.            return View();  
    24.  
    25.        }

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: How to bind sales header model to collection of sales Footer

    As for your issue, you don't need to get the two separately. When you get the root entity from EF, you can use the Include method to specify related entities to retrieve as well. Here's an example from a current project I'm working on:
    csharp Code:
    1. var aspNetUser = await dbContext.AspNetUsers
    2.                                 .Include(u => u.CreatedByUser)
    3.                                 .Include(u => u.UpdatedByUser)
    4.                                 .Include(u => u.RegistrationUser)
    5.                                 .Include(u => u.AspNetUserRoles)
    6.                                 .ThenInclude(ur => ur.Role)
    7.                                 .AsNoTracking()
    8.                                 .FirstOrDefaultAsync(u => u.Id == id);
    That's using EF Core but, if you're using EF 6, it should be pretty similar. I'm not sure that EF6 has ThenInclude but you can just provide a navigation path in the Include method.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to bind sales header model to collection of sales Footer

    ok thank you for reply
    and how to show list on view of edit

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to bind sales header model to collection of sales Footer

    ok thank you for reply
    and how to show list on view of edit

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: How to bind sales header model to collection of sales Footer

    The same way you display any other data. If you're displaying one record then you hard-code each field and if you are displaying a list of records then you use a loop. In this case you are doing both so you do both.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to bind sales header model to collection of sales Footer

    and from which place i will get data on list that I will loop on it

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: How to bind sales header model to collection of sales Footer

    Quote Originally Posted by engbarbary View Post
    and from which place i will get data on list that I will loop on it
    I don't understand how you can be asking me that. Did someone else write post #1 for you?

    Quote Originally Posted by engbarbary View Post
    so that i already have model Sales Header have navigation property to Sales Footer as following

    SalesHeader Model

    Code:
    public int SalesOrderNo { get; set; } 
    public int SalesYear { get; set; } 
    public ICollection<SalesFooter> SalesFooters { get; set; }
    What exactly do you think that is?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to bind sales header model to collection of sales Footer

    what i understand on first query get data of master details and after that how to get these data from query to list
    this is myquestion

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to bind sales header model to collection of sales Footer

    what i understand on first query get data of master details and after that how to get these data from query to list
    this is my question

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2018
    Posts
    67

    Re: How to bind sales header model to collection of sales Footer

    thank you it solved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width