hello
how i can updating total of master when each one detail have been inserted /updated/deleted, and not all details of master?
if i used repository for master and repository of details, and if these repositories implements IDisposable, how to use the tow repositories with each their save methode to updating master total with unitprice of this detail in class BLL?
What I have tried:
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;}
public private ICollection<Detail> Details {get; set;}
}
public class Detail
{
public int Id {get; set;}
public decimal UnitePrice {get; set;}
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{
}
public class DetailRepository : IDetailRepository{
EFContext context = new EFContext();
public IEnumerableDetail GetAllDetailsByMasterId(int masterId)
{
var query = context.Details.Where(d=>d.MasterId == masterId)
}
}
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(){
using (var repository = new DetailRepository())
{
var total = reopsitory.GetAllDetailsByMasterId(masterId).Sum(d=>d.UnitePrice);
}
}
}
I would be grateful if you helped me
goodby soon