public IHttpActionResult GetAdjustmentEntry(int itemId, int empId) { //Create SelectListItem for voucher List <SelectListItem> existingVouchers = new List <SelectListItem>(); // get the item ItemCatalogue itemCatalogue; using (var db = new ADProjectDb()) { itemCatalogue = inventoryService.GetItemCatalogue(db, itemId); //get list of existing Adjustment voucher raised by current employee and status is draft List <AdjustmentVoucher> voucherList = inventoryService.GetAdjustmentVoucherListByEmpIdStatusId(db, empId, 1); //Create a Json that send the exisiting Voucher list and viewInventory (I just need the item id and description). AdjustmentEntry adjustmentEntry = new AdjustmentEntry() { itemDesc = itemCatalogue.ItemDes, itemId = itemCatalogue.ItemCatalogueId }; int[] existingvoucherId = new int[voucherList.Count]; for (int i = 0; i < voucherList.Count; i++) { existingvoucherId[i] = voucherList[i].AdjustmentVoucherId; } adjustmentEntry.voucherId = existingvoucherId; if (adjustmentEntry == null) { return(NotFound()); } return(Ok(adjustmentEntry)); } }
public ActionResult CreatePO(string Supplier) { int selectedSupplierId = Int32.Parse(Supplier); Order newOrder; Employee employee = Session["employee"] as Employee; // Save to database using (var db = new ADProjectDb()) { Supplier selectedSupplier = orderService.GetSupplier(db, selectedSupplierId); // create new PO object with SupplierId and EmpId OrderStatus orderStatusDraft = db.OrderStatus.Where(x => x.OrderStatusId == 1).FirstOrDefault(); newOrder = new Order() { EmpId = employee.EmployeeId, SupplierId = selectedSupplier.SupplierId, Supplier = selectedSupplier, OrderStatus = orderStatusDraft }; db.Order.Add(newOrder); db.SaveChanges(); // Get back the last added order, need its orderId newOrder = db.Order.OrderByDescending(o => o.OrderId).FirstOrDefault(); } // Redirect to the viewPO page return(RedirectToAction("ViewPO", new { orderId = newOrder.OrderId, returnController = "Inventory", returnMethod = "showLowStock" })); }
public ActionResult Edit(Container container) { var db = new ADProjectDb(); Employee employee = Session["employee"] as Employee; List <Container> containers = disbursementService.GetContainers(db); Container targetContainer = containers.Where(ce => ce.DisbursementDetail.DisbursementDetailId == container.DisbursementDetail.DisbursementDetailId) .SingleOrDefault(); ViewData["container"] = targetContainer; List <Container> otherContainers = containers.Where(ce => ce.ItemCatalogue.ItemCatalogueId == container.ItemCatalogue.ItemCatalogueId) .Where(ce => ce.Department.DepartmentId != targetContainer.Department.DepartmentId) .Distinct().ToList(); List <SelectListItem> selectListOtherDepartments = otherContainers.Select(ce => new SelectListItem { Text = ce.Department.DepName + " | DibursementDetail Id: " + ce.DisbursementDetail.DisbursementDetailId.ToString(), Value = ce.DisbursementDetail.DisbursementDetailId.ToString() }).ToList(); ViewData["selectListOtherDepartments"] = selectListOtherDepartments; return(View()); }
public List <ViewDelivery> GetViewDeliveryList(ADProjectDb db) { // get list of all order details List <ViewDelivery> viewDeliveries = (from IC in db.ItemCatalogue join OD in db.OrderDetail on IC.ItemCatalogueId equals OD.ItemId join SI in db.StockInfo on IC.ItemCatalogueId equals SI.ItemCatalogueId join O in db.Order on OD.OrderId equals O.OrderId orderby OD.ItemId select new ViewDelivery() { supplierName = O.Supplier.SupplierName, orderId = OD.OrderId, itemId = IC.ItemCatalogueId, description = IC.ItemDes, quantity = OD.OrderQuantity, unit = IC.UnitOfMeasure, ExpDate = OD.ExpDelDate, ActDate = OD.ActDelDate }).ToList(); // get list of all order details with NULL Actual delivery date viewDeliveries = viewDeliveries.Where(S => S.ActDate == null).ToList(); return(viewDeliveries); }
// show adjustment, single entry public ActionResult ShowAdjustmentEntry(int itemId) { Employee employee = Session["employee"] as Employee; //Create SelectListItem for voucher List <SelectListItem> existingVouchers = new List <SelectListItem>(); // get the item ItemCatalogue itemCatalogue; using (var db = new ADProjectDb()) { itemCatalogue = inventoryService.GetItemCatalogue(db, itemId); //get list of existing Adjustment voucher raised by current employee and status is draft //Make sure the voucher id is autogenerate so that the first one is the latest voucher List <AdjustmentVoucher> voucherList = inventoryService.GetAdjustmentVoucherListByEmpIdStatusId(db, employee.EmployeeId, 1); // Fill up select list foreach (AdjustmentVoucher V in voucherList) { existingVouchers.Add(new SelectListItem() { Text = V.AdjustmentVoucherId.ToString(), Value = V.AdjustmentVoucherId.ToString() }); } //Send list of voucher to view for user to select ViewBag.VoucherList = voucherList; // Send current time ViewData["date"] = DateTime.Now.ToShortDateString(); ViewData["existingVouchers"] = existingVouchers; } // pass catalogue item to the view return(View(itemCatalogue)); }
public ActionResult Index(Department department, CollectionPoint collectionPoint, int?page) { using (var db = new ADProjectDb()) { List <Container> containers = disbursementService.GetContainers(db) ?? new List <Container>(); List <Container> selectListContainers = containers.ConvertAll(ce => ce).ToList(); //deep copy SelectList_Department_DisbursementStatus_CollectionPoints(db, selectListContainers); DisbursementStatus collectedDisbursementStatus = db.DisbursementStatus.Where(ds => ds.Description == StatusEnums.DisbursementStatusEnum.COLLECTED.ToString()).SingleOrDefault(); ViewData["collectedDisbursementStatus"] = collectedDisbursementStatus; if (collectionPoint.CollectionPointId != 0) { containers = containers.Where(ce => ce.CollectionPoint.CollectionPointId == collectionPoint.CollectionPointId) .ToList(); } if (department.DepartmentId != 0) { containers = containers.Where(ce => ce.Department.DepartmentId == department.DepartmentId) .ToList(); } ViewData["results"] = containers; int pageSize = 5; int pageNumber = (page ?? 1); return(View(containers.ToPagedList(pageNumber, pageSize))); } }
public List <Container> GetContainersForIndex(ADProjectDb db, int?employeeId = null) { using (db) { Employee employee = null; if (employeeId == null) { employee = GetEmployee(db); } else { employee = db.Employee.Where(emp => emp.EmployeeId == employeeId).SingleOrDefault(); } List <Container> containers = (from rd in db.RequestDetail join item in db.ItemCatalogue on rd.ItemCatalogue.ItemCatalogueId equals item.ItemCatalogueId where rd.Request.Department.DepartmentId == employee.DepartmentId where rd.Request.RequestStatus.RequestStatusDescription != RequestStatusEnum.DELIVERED.ToString() select new Container { RequestDetail = rd, Request = rd.Request, RequestStatus = rd.Request.RequestStatus, ItemCatalogue = item, Category = item.Category, CollectionPoint = rd.Request.CollectionPoint }).ToList(); return(containers); } }
//add adjustment, single entry, to an voucher public ActionResult SubmitAdjustmentEntry(int adjusQty, string VoucherReason, string SelectedVoucher, int ItemId) { // create new voucher detail object AdjustmentDetail adjustmentDetail = new AdjustmentDetail() { ItemCatalogueId = ItemId, Reason = VoucherReason, Quantity = adjusQty }; //Update adjustmentVoucher with new dsetail int VoucherId = Int32.Parse(SelectedVoucher); using (var db = new ADProjectDb()) { //Check if entry existed bool IsExisted = inventoryService.CheckifAdjExist(db, ItemId, VoucherId); if (IsExisted == true) { inventoryService.UpdateAdjDetails(db, ItemId, VoucherId, adjusQty, VoucherReason); } else { inventoryService.AddtoAdjustmentVoucher(db, VoucherId, adjustmentDetail); } } // redirect back to inventory list return(RedirectToAction("showLowStock", "Inventory")); }
public List <Container> GetCollectRequestedItems(ADProjectDb db, int?employeeId = null) { Employee employee; if (employeeId == null) { employee = GetEmployee(db); } else { employee = db.Employee.Where(emp => emp.EmployeeId == employeeId).SingleOrDefault(); } List <Container> containers = (from dd in db.DisbursementDetail join rd in db.RequestDetail on dd.Disbursement.RequestId equals rd.RequestId where rd.Request.DepartmentId == employee.DepartmentId where dd.DisbursementStatus.Description == DisbursementStatusEnum.READY_FOR_COLLECTION.ToString() where rd.Request.RequestStatus.RequestStatusDescription != RequestStatusEnum.DELIVERED.ToString() select new Container { DisbursementDetail = dd, RequestDetail = rd, Request = rd.Request, RequestStatus = rd.Request.RequestStatus, ItemCatalogue = rd.ItemCatalogue, CollectionPoint = dd.Disbursement.CollectionPoint, DisbursementStatus = dd.DisbursementStatus }).ToList(); return(containers); }
public void UpdateCollectionPointForAllRequest(ADProjectDb db, int collectionPointId, int?employeeId = null) { int departmentId = (int)GetEmployee(db).DepartmentId; if (employeeId != null) { departmentId = (int)db.Employee .Where(emp => emp.EmployeeId == employeeId) .Select(emp => emp.DepartmentId) .FirstOrDefault(); } List <Request> requests = db.Request.Where(r => r.DepartmentId == departmentId).ToList(); CollectionPoint collectionPoint = db.CollectionPoint .Where(cp => cp.CollectionPointId == collectionPointId) .SingleOrDefault(); requests.ForEach(r => r.CollectionPoint = collectionPoint); List <Disbursement> disbursements = db.DisbursementDetail .Where(dd => dd.DisbursementStatus.Description != DisbursementStatusEnum.READY_FOR_COLLECTION.ToString()) .Select(dd => dd.Disbursement) .ToList(); disbursements.ForEach(d => d.CollectionPoint = collectionPoint); db.SaveChanges(); }
public void AddtoAdjustmentVoucher(ADProjectDb db, int voucherId, AdjustmentDetail AD) { // Update cost of adjustmentDetail double price = (from IC in db.ItemCatalogue join SC in db.SupplierCatalogue on IC.ItemCatalogueId equals SC.ItemId where SC.SupplierRank == 1 where IC.ItemCatalogueId == AD.ItemCatalogueId select SC.ItemPrice).FirstOrDefault(); AD.Cost = AD.Quantity * price; //Add to AdjustmentDetail Database db.AdjustmentDetail.Add(AD); AdjustmentVoucher adjustmentVoucher = db.AdjustmentVoucher.Where(x => x.AdjustmentVoucherId == voucherId).FirstOrDefault(); if (adjustmentVoucher != null) { if (adjustmentVoucher.AdjustmentDetail == null) { adjustmentVoucher.AdjustmentDetail = new List <AdjustmentDetail>(); } adjustmentVoucher.AdjustmentDetail.Add(AD); } db.SaveChanges(); }
public IHttpActionResult GetCredential(string username, string password) { using (var db = new ADProjectDb()) { LoginResponse loginResponse; Employee validatedEmployee = authenticationServices.GetAuthenticatedEmployee(db, username, password); if (validatedEmployee != null) { loginResponse = new LoginResponse() { authenticationStatus = "Authenticated", role = validatedEmployee.Role.RoleDescription, username = validatedEmployee.Username, password = validatedEmployee.Password, empId = validatedEmployee.EmployeeId }; } else { loginResponse = new LoginResponse() { authenticationStatus = "Unauthenticated" }; } return(Ok(loginResponse)); } }
public ActionResult ViewVoucherDetail(string deleteid, string issubmit) { var db = new ADProjectDb(); AdjustmentVoucher adjustment = (AdjustmentVoucher)Session["newvoucher"]; List <AdjustmentDetail> details = (List <AdjustmentDetail>)Session["details"]; List <string> items = (List <string>)Session["des"]; if (deleteid != null) { for (int i = 0; i < details.Count; i++) { if (details[i].ItemCatalogueId.ToString() == deleteid) { details.Remove(details[i]); items.Remove(items[i]); } } } if (issubmit == "yes") { db.AdjustmentVoucher.Add(adjustment); for (int i = 0; i < details.Count(); i++) { db.AdjustmentDetail.Add(details[i]); } db.SaveChanges(); Session["detail"] = null; Session["newvoucher"] = null; return(RedirectToAction("ViewAllVouchers", "AdjustmentVoucher")); } ViewData["details"] = details; ViewData["itemdes"] = items; return(View()); }
public ActionResult SaveApproval(int?itemCatalogueId, int?quantity, int?requestId, int?requestStatusId, int?collectionPointId = 1) { using (var db = new ADProjectDb()) { Request request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); RequestStatus requestStatus = db.RequestStatus.Where(rs => rs.RequestStatusId == requestStatusId).SingleOrDefault(); request.RequestStatus = requestStatus; db.SaveChanges(); string APPROVED = StatusEnums.RequestStatusEnum.APPROVED.ToString(); //Only if Request is approved, then create Disbursement if (requestStatus.RequestStatusDescription == APPROVED) { if (AlreadyHasDisbursement((int)requestId) == false) { departmentHeadService.CreateDisbursementForApprovedRequest(db, (int)requestId, (int)collectionPointId, (int)quantity, (int)itemCatalogueId); } } if (requestStatus.RequestStatusDescription != APPROVED) { if (AlreadyHasDisbursement((int)requestId)) { departmentHeadService.DeleteDisbursementForDisapprovedRequest(db, (int)requestId); } } return(RedirectToAction("ApproveRequest", "DepartmentHead")); } }
public List <ViewOrder> GetAllOrdersAndFilterBySearch(ADProjectDb db, string search, int empId) { List <ViewOrder> viewOrders = (from O in db.Order join OS in db.OrderStatus on O.OrderStatus.OrderStatusId equals OS.OrderStatusId join S in db.Supplier on O.SupplierId equals S.SupplierId where O.EmpId == empId orderby O.OrderId select new ViewOrder() { orderId = O.OrderId, supplier = S.SupplierName, orderDate = O.OrderDate, status = OS.OrderDes, }).ToList(); // Filter if there is a search term passed to method if (!String.IsNullOrEmpty(search)) { viewOrders = viewOrders.Where(S => S.supplier.Contains(search) || S.status.Contains(search)).ToList(); } return(viewOrders); }
// GET: Representative public ActionResult Index() { using (var db = new ADProjectDb()) { List <Container> containers = representativeService.GetContainers(db); int totalQuantity = containers.Sum(ce => ce.RequestDetail.Quantity); CollectionPoint currentCollectionPoint = representativeService.GetLatestCollectionPoint(db); List <SelectListItem> selectListCollectionPoints = db.CollectionPoint .Select(cp => new SelectListItem { Value = cp.CollectionPointId.ToString(), Text = cp.Location, Selected = cp.CollectionPointId == currentCollectionPoint.CollectionPointId ? true : false }).ToList(); ViewData["totalQuantity"] = totalQuantity; ViewData["containers"] = containers; ViewData["selectListCollectionPoints"] = selectListCollectionPoints; ViewData["currentCollectionPoint"] = currentCollectionPoint; return(View()); } }
public List <RequisitionInfo> GetRequisitionInfos(ADProjectDb db) { List <RequisitionInfo> requisitionInfos = (from r in db.Request join rd in db.RequestDetail on r.RequestId equals rd.RequestId join item in db.ItemCatalogue on rd.ItemCatalogueId equals item.ItemCatalogueId join dep in db.Department on r.DepartmentId equals dep.DepartmentId join em in db.Employee on r.ApprByEmp.EmployeeId equals em.EmployeeId join rs in db.RequestStatus on r.RequestStatusId equals rs.RequestStatusId select new RequisitionInfo() { RequisitionNo = r.RequestId, ItemId = item.ItemCatalogueId, Description = item.ItemDes, Quantity = rd.Quantity, Unit = item.UnitOfMeasure, DepartmentName = dep.DepName, DepartmentId = dep.DepartmentId, RaisedBy = em.LastName + em.FirstName, RequestDate = r.RequestDate, Status = rs.RequestStatusDescription }).ToList(); return(requisitionInfos); }
public void DeleteOrder(ADProjectDb db, int orderId) { // get the Order to delete and commit ADProject.Models.Order toDelete = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault(); db.Order.Remove(toDelete); db.SaveChanges(); }
public List <ViewOrderDetail> GetViewOrderDetailList(ADProjectDb db, int orderId) { List <ViewOrderDetail> viewOrderDetails = (from IC in db.ItemCatalogue join OD in db.OrderDetail on IC.ItemCatalogueId equals OD.ItemId where OD.OrderId == orderId join SC in db.SupplierCatalogue on IC.ItemCatalogueId equals SC.ItemId join O in db.Order on OD.OrderId equals O.OrderId where SC.SupplierId == O.SupplierId orderby OD.ItemId select new ViewOrderDetail() { orderId = OD.OrderId, itemId = IC.ItemCatalogueId, description = IC.ItemDes, orderQty = OD.OrderQuantity, price = SC.ItemPrice, unit = IC.UnitOfMeasure, expDate = OD.ExpDelDate, actDate = OD.ActDelDate }).ToList(); return(viewOrderDetails); }
public Models.Order CreateNewOrderWithSupplierWithFirstOrderDetail(ADProjectDb db, int empId, string supplier, int itemId) { Supplier selectedSupplier = GetSupplierByName(db, supplier); ItemCatalogue firstitem = GetItemCatalogue(db, itemId); // create new PO object with SupplierId and EmpId OrderStatus orderStatusDraft = db.OrderStatus.Where(x => x.OrderStatusId == 1).FirstOrDefault(); ADProject.Models.Order newOrder = new ADProject.Models.Order() { EmpId = empId, SupplierId = selectedSupplier.SupplierId, Supplier = selectedSupplier, OrderStatus = orderStatusDraft }; db.Order.Add(newOrder); //Need to save changes first so that the new order id will be generated db.SaveChanges(); // Get back the last added order, need its orderId newOrder = db.Order.OrderByDescending(o => o.OrderId).FirstOrDefault(); //Get the reordering qty var reorder = db.StockInfo.Where(x => x.ItemCatalogueId == itemId).FirstOrDefault().ReOrderQuantity; // Create and add the new orderdetail, qty is the default restock quantity OrderDetail firstOd = new OrderDetail() { OrderId = newOrder.OrderId, ItemId = itemId, ItemCatalogue = firstitem, OrderQuantity = reorder }; db.OrderDetail.Add(firstOd); newOrder.OrderDetails = new List <OrderDetail>(); newOrder.OrderDetails.Add(firstOd); db.SaveChanges(); return(newOrder); }
public Employee getTargetEmployeeWithAssignedRole(ADProjectDb db, int employeeId) { Employee targetEmployee = db.Employee .Where(e => e.EmployeeId == employeeId) .SingleOrDefault(); AssignRole assignRole = db.Employee .Where(e => e.EmployeeId == employeeId) .Select(e => e.AssignRole).FirstOrDefault(); Role assignedRole_Role = null; try { assignedRole_Role = db.AssignRole.Where(ar => ar.EmployeeId == employeeId) .Select(ar => ar.Role).FirstOrDefault(); assignRole.Role = assignedRole_Role; } catch (Exception exception) { Debug.WriteLine(exception); } targetEmployee.AssignRole = assignRole; return(targetEmployee); }
public void SaveDelegation(ADProjectDb db, int delegatedEmployeeId, DateTime startDate, DateTime endDate, int assignedRoleId) { AssignRole assignRole = new AssignRole(); Employee delegatedEmployee = db.Employee .Where(emp => emp.EmployeeId == delegatedEmployeeId) .FirstOrDefault(); //One employee can only have 1 assigned role at a time if (delegatedEmployee.AssignRole != null) { DeleteDelegation(db, delegatedEmployeeId); } Employee departmentHead = GetDepartmentHead(db); assignRole.Employee = delegatedEmployee; assignRole.EmployeeId = delegatedEmployee.EmployeeId; assignRole.AssignedBy = departmentHead; assignRole.StartDate = startDate; assignRole.EndDate = endDate; assignRole.RoleId = assignedRoleId; delegatedEmployee.AssignRole = assignRole; db.SaveChanges(); }
public void CreateDisbursementForApprovedRequest(ADProjectDb db, int requestId, int?collectionPointId, int quantity, int itemCatalogueId) { Employee sessionEmployee = GetEmployee(db); Disbursement disbursement = new Disbursement(); DisbursementDetail disbursementDetail = new DisbursementDetail(); CollectionPoint collectionPoint = db.CollectionPoint.Where(cp => cp.CollectionPointId == collectionPointId).SingleOrDefault(); Employee employee = sessionEmployee; DisbursementStatus disbursementStatus = db.DisbursementStatus.Where(ds => ds.Description == "PENDING").SingleOrDefault(); ItemCatalogue itemCatalogue = db.ItemCatalogue.Where(ic => ic.ItemCatalogueId == itemCatalogueId).SingleOrDefault(); Request request = db.Request.Where(r => r.RequestId == requestId).SingleOrDefault(); disbursement.CollectionPoint = collectionPoint; disbursement.Department = employee.Department; disbursement.Employee = employee; disbursement.RequestId = requestId; disbursementDetail.DisbursementStatus = disbursementStatus; disbursementDetail.DisburseQuantity = quantity; disbursementDetail.Disbursement = disbursement; disbursementDetail.ItemCatalogue = itemCatalogue; request.CollectionPoint = collectionPoint; db.Disbursement.Add(disbursement); db.DisbursementDetail.Add(disbursementDetail); db.SaveChanges(); }
public ActionResult ViewPastRecord(int?page, string searchstring, string status) { ViewData["searchstring"] = searchstring; ViewData["status"] = status; int pageSize = 3; int pageNumber = (page ?? 1); string type = ""; var db = new ADProjectDb(); List <RequisitionInfo> requisitionInfos = adjustmentVoucherServices.GetRequisitionInfos(db); if (searchstring != null) { if (searchstring != "") { requisitionInfos = requisitionInfos.Where(re => re.DepartmentName.ToLower().Contains(searchstring.ToLower())).ToList(); } } if (status != null) { requisitionInfos = requisitionInfos.Where(re => re.Status == status).ToList(); } if (requisitionInfos.Count() == 0) { type = "zero"; } ViewData["type"] = type; return(View(requisitionInfos.ToPagedList(pageNumber, pageSize))); }
public ActionResult ViewAllVouchers(int?page, string status) { var db = new ADProjectDb(); List <SelectListItem> selectListAdjustmentStatus = db.AdjustmentStatus.Select(s => new SelectListItem { Text = s.Description, Value = s.Description }).ToList(); ViewData["selectListAdjustmentStatus"] = selectListAdjustmentStatus; ViewData["status"] = status; List <VoucherInfo> adjustments = adjustmentVoucherServices.GetAllVoucherInfo(db); if (string.IsNullOrEmpty(status) == false) { adjustments = adjustments.Where(x => x.Status == status).ToList(); } if (adjustments.Count == 0) { string type = "zero"; ViewData["type"] = type; } int pageSize = 3; int pageNumber = (page ?? 1); return(View(adjustments.ToPagedList(pageNumber, pageSize))); }
public async Task <ActionResult> PostToFlask(DateTime?startDate, int categoryId) { List <Container> containers = null; DateTime dateToPredict = startDate.GetValueOrDefault(); using (var db = new ADProjectDb()) { containers = dataAnalyticService.GetContainers(db); containers = containers.Where(ce => ce.CategoryId == categoryId).ToList(); } using (var client = new HttpClient()) { string jsonContent = await dataAnalyticService.GetJsonStringContentFromResponse(client, containers, dateToPredict); if (jsonContent != null) { //Logic to convert the json bytes into an image and save to Content/Images JObject json = JObject.Parse(jsonContent); string image = (string)json.GetValue("img"); double predictedQty = (double)json.GetValue("requested_pred_quantity"); double rsquare = (double)json.GetValue("rsquare"); string fileName = "graph.png"; SaveImageToFile(image, fileName); //Display the results to the razor page ViewData["predictedQty"] = predictedQty; ViewData["rsquare"] = rsquare; ViewData["image"] = fileName; } } return(View()); }
public IHttpActionResult GetDisbursementInfo(int collectionPointId, int departmentId, int disbursementStatusId) { using (var db = new ADProjectDb()) { List <DisbursementController.Container> containers = disbursementService.GetContainers(db) ?? new List <DisbursementController.Container>(); List <DisbursementController.Container> selectListContainers = containers.ConvertAll(ce => ce).ToList(); //deep copy Dictionary <int, string> collectionPoint = containers.Select(x => x.CollectionPoint) .Distinct() .Select(x => new KeyValuePair <int, string>(x.CollectionPointId, x.Location)) .ToDictionary(x => x.Key, x => x.Value); Dictionary <int, string> department = containers.Select(x => x.Department) .Distinct() .Select(x => new KeyValuePair <int, string>(x.DepartmentId, x.DepName)) .ToDictionary(x => x.Key, x => x.Value); Dictionary <int, string> disbursementStatus = containers.Select(x => x.DisbursementStatus) .Distinct() .Select(x => new KeyValuePair <int, string>(x.DisbursementStatusId, x.Description)) .ToDictionary(x => x.Key, x => x.Value); if (collectionPointId != 0) { containers = containers.Where(ce => ce.CollectionPoint.CollectionPointId == collectionPointId) .ToList(); } if (departmentId != 0) { containers = containers.Where(ce => ce.Department.DepartmentId == departmentId) .ToList(); } if (disbursementStatusId != 0) { containers = containers.Where(ce => ce.DisbursementStatus.DisbursementStatusId == disbursementStatusId).ToList(); } List <DisbursementInfo> listDI = containers .Select(x => new DisbursementInfo { requestId = x.RequestDetail.RequestId, disbursementdetailId = x.DisbursementDetail.DisbursementDetailId, itemDesc = x.ItemCatalogue.ItemDes, departmentName = x.Department.DepName, unitOfMeasurement = x.ItemCatalogue.UnitOfMeasure, requestQty = x.RequestDetail.Quantity, disbursementQty = x.DisbursementDetail.DisburseQuantity, collectionPoint = x.CollectionPoint.Location, disbursementStatus = x.DisbursementStatus.Description }).ToList(); // Put all into a container DisbursementPgContainer data = new DisbursementPgContainer() { collectionPtsSelectList = collectionPoint, DepartmentSelectList = department, DisbursementStatusSelectList = disbursementStatus, disbursementInfos = listDI }; // string Jsonresult = JsonConvert.SerializeObject(data); return(Ok(data)); } }
public ActionResult Save(int collectionPointId) { using (var db = new ADProjectDb()) { representativeService.UpdateCollectionPointForAllRequest(db, collectionPointId); } return(RedirectToAction("Index", "Representative")); }
public ActionResult AcceptDelivery(int requestId) { using (var db = new ADProjectDb()) { representativeService.SetRequestStatusToDelivered(db, requestId); } return(RedirectToAction("CollectRequestedItems", "Representative")); }
public void DeleteOrderDetail(ADProjectDb db, int orderId, int itemId) { //get Orderdetail from database and delete OrderDetail toDelete = db.OrderDetail.Where(x => x.OrderId == orderId).Where(x => x.ItemId == itemId).FirstOrDefault(); db.OrderDetail.Remove(toDelete); db.SaveChanges(); }