public DailySaleRecordModel Get(int dailySaleID) { using (var uow = new UnitOfWork(new DataContext())) { var objDailySaleRecord = uow.DailySaleRecords.Get(dailySaleID); // get total sales of outlets var outletTotalSale1 = uow.ProductSales.GetAllBy(objDailySaleRecord.CreateDateTime, "Outlet Sale 1", excludeProduct: "Raw Milk") .Select(x => new { Quantity = x.Quantity, UnitPrice = x.UnitPrice, Discount = x.Discount }) .Sum(x => (x.Quantity * x.UnitPrice) - (x.Discount * x.Quantity)); // get total sales of outlets var outletTotalSale2 = uow.ProductSales.GetAllBy(objDailySaleRecord.CreateDateTime, "Outlet Sale 2", excludeProduct: "Raw Milk") .Select(x => new { Quantity = x.Quantity, UnitPrice = x.UnitPrice, Discount = x.Discount }) .Sum(x => (x.Quantity * x.UnitPrice) - (x.Discount * x.Quantity)); var rawMilkSales = uow.ProductSales.GetAllBy(objDailySaleRecord.CreateDateTime, "Raw Milk").Sum(x => x.Quantity * x.UnitPrice); var totalCashSale = outletTotalSale1 + outletTotalSale2 + objDailySaleRecord.ProcessingSale; var totalSaleDairyProduct = totalCashSale + objDailySaleRecord.SaleOnAccount; var totalSale = totalSaleDairyProduct + rawMilkSales; var model = new DailySaleRecordModel(); model.Date = objDailySaleRecord.CreateDateTime; model.OutletSale1 = outletTotalSale1; model.OutletSale2 = outletTotalSale2; model.ProcessingSale = objDailySaleRecord.ProcessingSale; model.RawMilkSales = rawMilkSales; model.SaleOnAccount = objDailySaleRecord.SaleOnAccount; model.TotalCashSales = totalCashSale; model.TotalSaleForDairyProduct = totalSaleDairyProduct; model.TotalSales = totalSale; model.Debtor = objDailySaleRecord.Debtor; return(model); } }
public void Edit(int id, DailySaleRecordModel model) { using (var uow = new UnitOfWork(new DataContext())) { var obj = uow.DailySaleRecords.Get(id); obj.Debtor = model.Debtor; obj.ProcessingSale = model.ProcessingSale; obj.SaleOnAccount = model.SaleOnAccount; uow.DailySaleRecords.Edit(obj); uow.Complete(); } }
public void Add(DailySaleRecordModel model) { using (var uow = new UnitOfWork(new DataContext())) { var obj = new DailySaleRecord(); obj.CreateDateTime = model.Date; obj.Debtor = model.Debtor; obj.ProcessingSale = model.ProcessingSale; obj.SaleOnAccount = model.SaleOnAccount; uow.DailySaleRecords.Add(obj); uow.Complete(); model.ID = obj.DailySaleRecordID; } }
public void Save() { try { if (!ValidateFields()) { LocalUtils.ShowValidationFailedMessage(this); } else { var model = new DailySaleRecordModel(); model.Debtor = txtDebtor.Text; model.Date = dtDate.Value; model.ProcessingSale = LocalUtils.ConvertToDouble(txtProcessingSale.Text); model.SaleOnAccount = LocalUtils.ConvertToDouble(txtSalesOnAccount.Text); // get id if (dailySaleID != 0) { Factories.CreateDailySale().Edit(dailySaleID, model); LocalUtils.ShowSaveMessage(this); } else { Factories.CreateDailySale().Add(model); dailySaleID = model.ID; LocalUtils.ShowSaveMessage(this); } } } catch (ApplicationException ex) { LocalUtils.ShowErrorMessage(this, ex.Message); } catch (Exception ex) { LocalUtils.ShowErrorMessage(this, ex.ToString()); } }