public async Task <ActionResult> CashManagement([Bind(Include = "TerminalId,Status,Partner,PartnerId,Group,GroupId")] CashManagementViewModel vmodel) { ModelState.Remove("PartnerId"); ModelState.Remove("GroupId"); ModelState.Remove("TerminalId"); if (ModelState.IsValid) { List <CashManagementTableVM> listaux = new List <CashManagementTableVM>(); List <JsonLoadCashChart> listchart = new List <JsonLoadCashChart>(); List <JsonCashManagement> list = new List <JsonCashManagement>(); ApiATM api = new ApiATM(); string[] listtn = ListTerminalByGroup(vmodel.GroupId); list = await api.CashManagement(vmodel.TerminalId, listtn); IEnumerable <dynamic> listTn = repo_terminal.LoadCashMngList(list, vmodel.Status, vmodel.PartnerId, Convert.ToInt32(Session["partnerId"])); if (listTn.Count() > 0) { foreach (var item in listTn) { int? cashBalance = list.Where(m => m.TerminalId == item.TerminalId).Select(m => m.CashBalance).FirstOrDefault(); int? amountPrevius = list.Where(m => m.TerminalId == item.TerminalId).Select(m => m.AmountPrevius).FirstOrDefault(); int? amountLoad = list.Where(m => m.TerminalId == item.TerminalId).Select(m => m.AmountLoad).FirstOrDefault(); int? amountCurrent = list.Where(m => m.TerminalId == item.TerminalId).Select(m => m.AmountCurrent).FirstOrDefault(); int? dayuntilcashload = list.Where(m => m.TerminalId == item.TerminalId).Select(m => m.Dayuntilcashload).FirstOrDefault(); DateTime?lastLoad = list.Where(m => m.TerminalId == item.TerminalId).Select(m => m.LastLoad).FirstOrDefault(); CashManagementTableVM obj = new CashManagementTableVM(item.TerminalId, item.LocationName, cashBalance.ToString(), dayuntilcashload.ToString(), lastLoad.ToString(), amountPrevius.ToString(), amountLoad.ToString(), amountCurrent.ToString()); JsonLoadCashChart objchart = new JsonLoadCashChart(lastLoad?.ToString("yyyy-MM-dd"), amountPrevius, amountLoad); listchart.Add(objchart); listaux.Add(obj); } } #region Variables Partial TempData["List"] = listaux.Count() > 0 ? Utils.ToDataTable <CashManagementTableVM>(listaux) : null; TempData["filename"] = "CashManagement"; TempData["Chart"] = listchart.Count() > 0 ? JsonConvert.SerializeObject(listchart) : null; TempData["terminal"] = vmodel.TerminalId; TempData["partner"] = vmodel.Partner; TempData["Sub"] = false; #endregion Session["businessName"] = ""; return(View("CashManagement/CashManagement")); } return(RedirectToAction("Index")); }
public async Task <ActionResult> CashLoad([Bind(Include = "TerminalId,StartDate,EndDate,Status,Partner,PartnerId,Group,GroupId")] CashLoadViewModel vmodel) { ModelState.Remove("PartnerId"); ModelState.Remove("GroupId"); ModelState.Remove("TerminalId"); if (ModelState.IsValid) { List <CashLoadTableVM> listaux = new List <CashLoadTableVM>(); List <JsonLoadCashChart> listchart = new List <JsonLoadCashChart>(); List <JsonLoadCash> list = new List <JsonLoadCash>(); ApiATM api = new ApiATM(); DateTime?start = DateTime.ParseExact(vmodel.StartDate, "MM/dd/yyyy", CultureInfo.InvariantCulture); DateTime?end = DateTime.ParseExact(vmodel.EndDate, "MM/dd/yyyy", CultureInfo.InvariantCulture); string[] listtn = ListTerminalByGroup(vmodel.GroupId); list = await api.CashLoad(start, end, vmodel.TerminalId, listtn); IEnumerable <dynamic> listTn = repo_terminal.LoadCashList(list, vmodel.Status, vmodel.PartnerId, Convert.ToInt32(Session["partnerId"])); if (listTn.Count() > 0) { foreach (var item in list) { string locationname = ""; foreach (dynamic x in listTn) { if (x.TerminalId == item.TerminalId) { locationname = x.LocationName; break; } } if (locationname != "") { CashLoadTableVM obj = new CashLoadTableVM(item.TerminalId, locationname, item.Date, item.AmountPrevius.ToString(), item.AmountLoad.ToString(), item.AmountCurrent.ToString()); JsonLoadCashChart objchart = new JsonLoadCashChart(item.Date.ToString("yyyy-MM-dd"), item.AmountPrevius, item.AmountLoad); listchart.Add(objchart); listaux.Add(obj); } } } #region Variables Partial TempData["List"] = listaux.Count() > 0 ? Utils.ToDataTable <CashLoadTableVM>(listaux) : null; TempData["filename"] = "CashLoad"; TempData["Chart"] = listchart.Count() > 0 ? JsonConvert.SerializeObject(listchart) : null; TempData["terminal"] = vmodel.TerminalId; TempData["partner"] = vmodel.Partner; TempData["from"] = vmodel.StartDate; TempData["to"] = vmodel.EndDate; TempData["Sub"] = false; #endregion return(View("CashLoad/CashLoad")); } return(RedirectToAction("Index")); }