public ActionResult CreateOrder(FormCollection collection) { var count = collection.Count; var supplier = collection["Supplier"]; var requestLineIds = new List <int>(); for (int i = 0; i < count - 1; i++) { var requestLineId = collection[i]; if (requestLineId.Contains("true")) { requestLineIds.Add(Convert.ToInt32(collection.Keys[i])); } } var orderNumber = getOrderNumber(); DateTime createdDate = DateTime.Now; //Used for dummy orders DateTime expectedDate = createdDate.AddDays(5); var supplierId = _context.StockRoomSuppliers.FirstOrDefault(x => x.Name == supplier).Id; var suplierContactId = _context.StockroomSupplierContacts.FirstOrDefault(x => x.StockRoomSupplierId == supplierId).Id; StockRoomOrder order = new StockRoomOrder() { OrderNumber = orderNumber, StockRoomSupplierId = supplierId, StockRoomSupplierContactId = suplierContactId, OrderPlaced = createdDate, OrderExpected = expectedDate, StatusLastUpDate = createdDate, StockRoomOrderStatusId = 0, OrderApproved = true }; _context.StockroomOrders.Add(order); _context.SaveChanges(); var requestLines = new List <StockRoomRequestLine>(); foreach (var requestlineId in requestLineIds) { var line = _context.StockroomRequestLines.FirstOrDefault(x => x.Id == requestlineId); var orderId = _context.StockroomOrders.FirstOrDefault(x => x.OrderNumber == orderNumber).Id; var indexId = +_context.StockroomSupplierPartIndexes.FirstOrDefault(x => x.ManufacturerPartId == line.ManufacturerPartId).Id; StockRoomOrderLine orderLine = new StockRoomOrderLine() { StockRoomOrderId = orderId, StockRoomSupplierPartIndexId = indexId, NumberOfItemsOrdered = line.Number, Approved = true }; _context.StockroomOrderLines.Add(orderLine); } _context.SaveChanges(); return(RedirectToAction("PartRequest")); }
public ActionResult CreateNewOrder(FormCollection collection) { var orderNumber = getOrderNumber(); DateTime createdDate = DateTime.Now; //Used for dummy orders DateTime expectedDate = createdDate.AddDays(5); var stockRoomId = Convert.ToInt32(collection["Inv.StockId"]); var quantityOrdered = collection["Line.NumberOfItemsOrdered"]; var stockId = _context.StockRoomInventories.FirstOrDefault(x => x.Id == stockRoomId).StockId; var partNumber = _context.StockRoomInventories.FirstOrDefault(x => x.StockId == stockId).ManufacturerPartId; var supplierId = _context.StockroomSupplierPartIndexes.FirstOrDefault(x => x.ManufacturerPartId == partNumber).StockRoomSupplierId; var contact = _context.StockroomSupplierContacts.FirstOrDefault(x => x.StockRoomSupplierId == supplierId).Id; var order = new StockRoomOrder() { OrderNumber = orderNumber, StockRoomSupplierId = supplierId, StockRoomSupplierContactId = contact, OrderPlaced = createdDate, OrderExpected = expectedDate, StatusLastUpDate = createdDate, StockRoomOrderStatusId = 0, OrderApproved = true }; _context.StockroomOrders.Add(order); _context.SaveChanges(); var orderId = _context.StockroomOrders.FirstOrDefault(x => x.OrderNumber == orderNumber).Id; var manPartId = _context.StockRoomInventories.FirstOrDefault(x => x.StockId == stockId).ManufacturerPartId; var indexId = _context.StockroomSupplierPartIndexes.FirstOrDefault(x => x.ManufacturerPartId == manPartId).Id; var line = new StockRoomOrderLine() { StockRoomOrderId = orderId, StockRoomSupplierPartIndexId = indexId, NumberOfItemsOrdered = Convert.ToInt32(quantityOrdered), Approved = true }; _context.StockroomOrderLines.Add(line); _context.SaveChanges(); return(RedirectToAction("CreateOrder")); }
public ActionResult HandlePartRequests(FormCollection collection) { if (collection.AllKeys.Contains("ApproveOrder")) { var partid = Convert.ToInt32(collection["ApproveOrder"].Split(',')[0]); var qty = Convert.ToInt32(collection["ApproveOrder"].Split(',')[1]); var requestId = Convert.ToInt32(collection["ApproveOrder"].Split(',')[2]); var updateInventory = _context.StockRoomInventories.FirstOrDefault(x => x.ManufacturerPartId == partid); var partsRequest = _context.StockRoomRequests.FirstOrDefault(x => x.Id == requestId); partsRequest.StockRoomRequestStatusId = 1; updateInventory.OnHand = updateInventory.OnHand - qty; _context.SaveChanges(); return(RedirectToAction("PartRequest")); } var count = collection.Count; //THIS ONLY WORKS IF USER SELECTS SAME SUPPLIER //this is a quick fix for altering the order process var supplier = collection["Supplier"].Split(',')[0]; var requestLineIds = new List <int>(); for (int i = 0; i < count - 1; i++) { var requestLineId = collection[i].Split(','); if (requestLineId.Contains("true")) { requestLineIds.Add(Convert.ToInt32(collection.Keys[i])); } } foreach (int id in requestLineIds) { var requestLine = _context.StockroomRequestLines.FirstOrDefault(x => x.Id == id); var partRequest = _context.StockRoomRequests.FirstOrDefault(x => x.Id == requestLine.StockRoomRequestId); partRequest.StockRoomRequestStatusId = 2; _context.SaveChanges(); } var orderNumber = getOrderNumber(); DateTime createdDate = DateTime.Now; //Used for dummy orders DateTime expectedDate = createdDate.AddDays(5); var supplierId = _context.StockRoomSuppliers.FirstOrDefault(x => x.Name == supplier).Id; var suplierContactId = _context.StockroomSupplierContacts.FirstOrDefault(x => x.StockRoomSupplierId == supplierId).Id; StockRoomOrder order = new StockRoomOrder() { OrderNumber = orderNumber, StockRoomSupplierId = supplierId, StockRoomSupplierContactId = suplierContactId, OrderPlaced = createdDate, OrderExpected = expectedDate, StatusLastUpDate = createdDate, StockRoomOrderStatusId = 0, OrderApproved = true }; _context.StockroomOrders.Add(order); _context.SaveChanges(); var requestLines = new List <StockRoomRequestLine>(); foreach (var requestlineId in requestLineIds) { var line = _context.StockroomRequestLines.FirstOrDefault(x => x.Id == requestlineId); var orderId = _context.StockroomOrders.FirstOrDefault(x => x.OrderNumber == orderNumber).Id; var indexId = +_context.StockroomSupplierPartIndexes.FirstOrDefault(x => x.ManufacturerPartId == line.ManufacturerPartId).Id; StockRoomOrderLine orderLine = new StockRoomOrderLine() { StockRoomOrderId = orderId, StockRoomSupplierPartIndexId = indexId, NumberOfItemsOrdered = line.Number, Approved = true }; _context.StockroomOrderLines.Add(orderLine); } _context.SaveChanges(); return(RedirectToAction("PartRequest")); }