private List <ToplineViewModel> BindToplinesViewModel(List <BPSR_Topline> toplines, DateTime dueDate, string approverName, bool isAdmin, bool isApprover) { var results = new List <ToplineViewModel>(); foreach (var t in toplines) { var item = new ToplineViewModel() { ToplineId = t.BPSR_ToplineID, StoreId = t.LocalStoreID, Status = FormatHelpers.FormatStatus(t.BPSR_StatusID), PeriodEndDate = FormatHelpers.FormatPeriodDate(t.PeriodEndDate), NetSales = FormatHelpers.FormatMoney(t.NetSales), FranCalcRoyalty = FormatHelpers.FormatMoney(t.FranCalcRoyalty), FranCalcAdvertising = FormatHelpers.FormatMoney(t.FranCalcAdvertising), TotalTickets = FormatHelpers.FormatNumber(t.TotalTickets), SalesTypeCode = FormatHelpers.FormatSalesType(t.SalesTypeID), //t.SalesType.SalesTypeCode, //FormatSalesType IsPastDue = this.IsPastDue(dueDate, t.PeriodEndDate), //CanEdit = this.CanEditTopline(t.BPSR_StatusID, isAdmin, isApprover), //CanApprove = this.CanApproveTopline(t.BPSR_StatusID, isAdmin, isApprover), //CanSubmit = this.CanSubmitTopline(t.BPSR_StatusID, isAdmin, isApprover) CanEdit = this.CanEditTopline(t.BPSR_StatusID, isAdmin, isApprover), CanApprove = this.CanApproveTopline(t.BPSR_StatusID, isAdmin, isApprover), CanSubmit = this.CanSubmitTopline(t.BPSR_StatusID, t.SubmitterName, approverName, isAdmin, isApprover) }; results.Add(item); } return(results); }
private List <ToplineProductGroupViewModel> BindToplineProductsGroupViewModel(IEnumerable <BPSR_ProdGrp> prodGrps, IEnumerable <ToplinePrdSubGrps_Result> availableToplinePrdSubGrps) { var results = new List <ToplineProductGroupViewModel>(); try { // trap and protect this potential exception due to data integrity issues (may not be unique) var dict = prodGrps.Where(s => s.ProdSubGrpID != null).ToDictionary(x => x.ProdSubGrpID, x => x); foreach (var p in availableToplinePrdSubGrps) { var v = new ToplineProductGroupViewModel() { ProdGrpID = p.ProdGrpID, ProdSubGrpID = p.ProdSubGrpID, Name = p.ProdSubGrpDescription }; if (dict.ContainsKey(p.ProdSubGrpID)) { var m = dict[p.ProdSubGrpID]; v.BPSR_ToplineID = m.BPSR_ToplineID; v.BPSR_ProdGrpID = m.BPSR_ProdGrpID; v.NetSales = FormatHelpers.FormatMoney(m.NetSales); v.FranCalcRoyalty = FormatHelpers.FormatMoney(m.FranCalcRoyalty); v.FranCalcAdvertising = FormatHelpers.FormatMoney(m.FranCalcAdvertising); v.TotalTickets = FormatHelpers.FormatNumber(m.TotalTickets); } results.Add(v); } } catch (Exception ex) { _log.Error(FormatException(ex)); } return(results); }
private EditToplineViewModel BindEditToplineViewModel(BPSR_Topline topline, IEnumerable <ToplinePrdSubGrps_Result> availableToplinePrdSubGrps, bool isAdmin, bool isApprover) { var model = new EditToplineViewModel() { ToplineId = topline.BPSR_ToplineID, StatusId = topline.BPSR_StatusID, LocalStoreId = topline.LocalStoreID, NetSales = FormatHelpers.FormatMoney(topline.NetSales), TotalTickets = FormatHelpers.FormatNumber(topline.TotalTickets), FranCalcRoyalty = FormatHelpers.FormatMoney(topline.FranCalcRoyalty), FranCalcAdvertising = FormatHelpers.FormatMoney(topline.FranCalcAdvertising), Title = FormatTitle("Enter Sales", topline.LocalStoreID, topline.PeriodEndDate), ProductGroups = BindToplineProductsGroupViewModel(topline.BPSR_ProdGrp, availableToplinePrdSubGrps), IsApprove = false, CanApprove = this.CanApproveTopline(topline.BPSR_StatusID, isAdmin, isApprover), SalesTypeId = topline.SalesTypeID, SalesTypeList = this.GetAvailableSalesTypeList(topline.SalesTypeID) }; return(model); }