public ActionResult PrintHBCostV(HouseBillListVm hbObj) { ViewBag.HbObj = hbObj; OperationCostMainVm hbCostView = HouseBillHelper.GetHBCost(hbObj.HouseBillId, 0); return(View(hbCostView)); }
internal static OperationCostMainVm GetHBCost(int houseBillId) { OperationsEntities db = new OperationsEntities(); var operCostDb = db.OperationCosts.Where(x => x.HouseBillId == houseBillId && x.IsAccounting == true).ToList(); OperationCostMainVm operCostMainVm = new OperationCostMainVm(); if (operCostDb.Count == 0) { OperationCostVm operCostVm = new OperationCostVm() { HouseBillId = houseBillId }; operCostMainVm.OperationCosts.Add(operCostVm); } else { OperationCostVm operCostVm; Mapper.CreateMap <OperationCost, OperationCostVm>().IgnoreAllNonExisting(); foreach (var item in operCostDb) { operCostVm = new OperationCostVm(); Mapper.Map(item, operCostVm); //if operation id = 0 .. view mode .. load all data var costLib = item.OperationCostLib; operCostVm.OperCostNameEn = costLib.OperCostNameEn; operCostVm.OperCostNameAr = costLib.OperCostNameAr; operCostVm.CurrencySign = item.Currency.CurrencySign; operCostMainVm.OperationCosts.Add(operCostVm); } OperationCostTotalsVm costTotals; var totalsObj = operCostMainVm.OperationCosts.GroupBy(g => g.CurrencySign) .Select(x => new { CurrSign = x.Key, TotalSelling = x.Sum(g => g.OperationCostSelling), TotalNet = x.Sum(g => g.OperationCostNet) }).ToList(); foreach (var item in totalsObj) { costTotals = new OperationCostTotalsVm() { CurrencySign = item.CurrSign, TotalCostNet = item.TotalNet, TotalCostSelling = item.TotalSelling }; operCostMainVm.Totals.Add(costTotals); } } return(operCostMainVm); }
public ActionResult GetHBCost(int houseBillId, int operationId) { ViewBag.OperationCostNameList = ListCommonHelper.GetOperationCostList(); ViewBag.CurrencyList = ListCommonHelper.GetCurrencyList(); ViewBag.HbObj = ((List <HouseBillListVm>)TempData["hbList"]).Where(x => x.HouseBillId == houseBillId).FirstOrDefault(); Session["hbOneObj"] = ((List <HouseBillListVm>)TempData["hbList"]).Where(x => x.HouseBillId == houseBillId).FirstOrDefault(); OperationCostMainVm hbCostAdd = HouseBillHelper.GetHBCost(houseBillId, operationId); return(PartialView("~/Views/Operation/_OperationCost.cshtml", hbCostAdd)); }
public ActionResult AddOperationCost(int hbId) { ViewBag.OperationCostNameList = ListCommonHelper.GetOperationCostList(); ViewBag.CurrencyList = ListCommonHelper.GetCurrencyList(); ViewBag.HbObj = HouseBillHelper.GetHbContent(hbId); // Session["hbOneObj"] = ((List<HouseBillListVm>)TempData["hbList"]).Where(x => x.HouseBillId == hbId).FirstOrDefault(); OperationCostMainVm hbCostAdd = HouseBillHelper.GetHBCost(hbId); return(View(hbCostAdd)); }
internal static string AddEditAccountHbCost(OperationCostMainVm operCostMainVm) { OperationsEntities db = new OperationsEntities(); var operCostVmList = operCostMainVm.OperationCosts; int hbId = operCostVmList.FirstOrDefault().HouseBillId; //Get costId sent from screen List <int> screenCostIds = operCostVmList.Select(x => x.OperCostId).ToList(); //Get db saved list var operCostDbList = db.OperationCosts.Where(x => x.HouseBillId == hbId && x.IsAccounting == true).ToList(); //delete removed items var costToDel = operCostDbList.Where(x => !screenCostIds.Contains(x.OperCostId)).ToList(); foreach (var item in operCostDbList) { db.OperationCosts.Remove(item); } //Map the Vm to db list Mapper.CreateMap <OperationCostVm, OperationCost>().IgnoreAllNonExisting(); Mapper.Map(operCostVmList, operCostDbList); string isSaved = "true"; using (TransactionScope transaction = new TransactionScope()) { try { db.SaveChanges(); using (var dbCtx = new OperationsEntities()) { foreach (var item in operCostDbList) { if (item.HouseBillId != 0) { dbCtx.OperationCosts.Add(item); } // else // dbCtx.Entry(item).State = System.Data.Entity.EntityState.Modified; } dbCtx.SaveChanges(); } transaction.Complete(); } catch (DbEntityValidationException e) { isSaved = "false " + e.Message; } catch (Exception e) { isSaved = "false " + e.InnerException; } } return(isSaved); }
public ActionResult AddEditAccountHbCost(OperationCostMainVm operCostMainVm) { string isSaved = HouseBillHelper.AddEditAccountHbCost(operCostMainVm); return(Json(isSaved)); }