public async Task <IActionResult> ApprovedOrders(DataSourceRequest command, ApproveOrderListModel model) { var(processOrderListModel, totalCount) = await _processOrderService.PrepareApproveOrderListModel(model, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = processOrderListModel, Total = totalCount }; return(Json(gridModel)); }
public async Task <(IEnumerable <ApproveOrderModel> processOrderListModel, int totalCount)> PrepareApproveOrderListModel(ApproveOrderListModel model, int pageIndex, int pageSize) { try { var usrType = (int)_workContext.CurrentCustomer.UserType; int sortBy = 0; //As per client VB Code switch (model.intSort) { case 1: //Sort by Cost Center if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 1; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 10; } else if (usrType == 7 || usrType == 10) { sortBy = 30; } else if (usrType == 15) { sortBy = 20; } break; case 2: //sort by date if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 2; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 11; } else if (usrType == 7 || usrType == 10) { sortBy = 31; } else if (usrType == 15) { sortBy = 21; } break; case 3: //sort by item # if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 3; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 12; } else if (usrType == 7 || usrType == 10) { sortBy = 32; } else if (usrType == 15) { sortBy = 22; } break; case 4: //sort by Vendor if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 4; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 13; } else if (usrType == 7 || usrType == 10) { sortBy = 33; } else if (usrType == 15) { sortBy = 23; } break; case 5: //orders Sent to Central Purchasing Sorted by Cost Center" sortBy = 40; break; case 6: //Orders Sent to Central Purchasing Sorted by Date sortBy = 41; break; case 7: //all transfered orders sorted by date sortBy = 42; break; case 8: //Orders Sent to Central Purchasing Sorted by Vendor sortBy = 43; break; case 9: //sort by quantity if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 5; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 14; } else if (usrType == 7 || usrType == 10) { sortBy = 34; } else if (usrType == 15) { sortBy = 24; } break; case 10: //sort by total expense if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 6; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 15; } else if (usrType == 7 || usrType == 10) { sortBy = 35; } else if (usrType == 15) { sortBy = 25; } break; case 11: //sort by total expense if (usrType == 1 || usrType == 3 || usrType == 4) { sortBy = 6; } else if (usrType == 2 || usrType == 6 || usrType == 8) { sortBy = 16; } else if (usrType == 7 || usrType == 10) { sortBy = 36; } else if (usrType == 15) { sortBy = 26; } break; } SqlParameter[] pr = new SqlParameter[] { new SqlParameter("@intClientID", (int)_workContext.CurrentCustomer.ClientId), new SqlParameter("@intLogonID", (int)_workContext.CurrentCustomer.LogonId), new SqlParameter("@intSort", sortBy) }; var orders = await _dbContext.Set <Orders>().FromSqlRaw("exec Preview @intClientID,@intLogonID,@intSort", pr).ToListAsync(); var approveOrderlist = new List <ApproveOrderModel>(); foreach (var order in orders) { approveOrderlist.Add(new ApproveOrderModel { OrdersId = order.OrdersId, VitemId = order.VitemId, Oitem = order.Oitem, Odescription = order.Odescription, Oqty = order.Oqty, DeptResp = order.DeptResp, OshipId = order.OshipId, OshipName = order.OshipName, Osid = order.Osid, OsellingPrice = order.OsellingPrice, Total = ((int)order.Oqty * Convert.ToDecimal(order.OsellingPrice)), OvendorId = order.OvendorId, OvendorName = order.OvendorName, Ogl = order.Ogl, Ouom = order.Ouom }); } int totalCount = approveOrderlist.Count; int pageOffSet = (Convert.ToInt32(pageIndex) - 1) * 10; approveOrderlist = approveOrderlist.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList(); return(approveOrderlist, totalCount); } catch (Exception ex) { } return(null, 0); }