Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

update master with sum record of details

$
0
0

hello

i have created solution in visual studio 2012 and this solution is layred in 4 project :

1. project presentation layer (asp.net mvc) 

2. business entities layer

public class Master
{
   public int Id {get; set;}
   public decimal TotalPrice {get; set;}
   //the rest of properties
   public private ICollection<Detail> Details {get; set;}
}

public class Detail
{
  public int Id {get; set;}
  public decimal UnitePrice {get; set;}
   //the rest of properties
  public int MasterId {get; set;}
  public private Master Master {get; set;}
}

3. data access layer (ado.net data model entity framework + repositories)

public class MasterRepository : IMasterRepository{
    //code of class to implemente GetAll + CRUD for master
}


public class DetailRepository : IDetailRepository{

   EFContext context = new EFContext();

  //Get the details for one master

   public IEnumerable<Detail> GetAllDetailsByMasterId(int masterId)
   {
      var query = context.Details.Where(d=>d.MasterId == masterId)
   }

  //the rest of code to implemente CRUD of details

}

4. but for business logic layer in classes Bll i try to calculate the total of the master by sum of unit prices for the details

public class MasterDetailsBll
{

   public decimal GetTotal(){

//call the methode GetAllDetailsByMasterId of DetailRepository thet return enumerebal<detail> and then call the extention methode Sum for calculate the sum of unite prices of detail

       using (var repository = new DetailRepository())
       {
         var total = reopsitory.GetAllDetailsByMasterId(masterId).Sum(d=>d.UnitePrice);
       }

//call the CRUD Mehodes of repositoryMaster and CRUD of the repositoryDetails } }

I am a beginner in .net and I do not know if working with a layered application is a good idea or not.

How I update total of master with sum of unit price after each insert/update of detail?

please help me


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>