public ViewResult Edit(int id) { var c = unitOfWork.CompanyRepository.GetByID(id); ViewData["billtocid"] = EZDropDown.Companies(unitOfWork, c.billtocid); return(View(c)); }
public ActionResult Edit([Bind(Include = "id, name, address, city, state, zip, billto, shipto, billtocid, email, password")] Company c) { try { ViewData["billtocid"] = EZDropDown.Companies(unitOfWork, c.billtocid); if (ModelState.IsValid) { if (c.billtocid == null) { ModelState.AddModelError("Required", "Required"); } else { db.Entry(c).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(View(c)); }
public ViewResult Edit(string sku) { var item = unitOfWork.ItemRepository.GetByID(sku); ViewData["companyid"] = EZDropDown.Companies(unitOfWork, item.companyid); return(View(item)); }
public ActionResult Create([Bind(Include = "sku, lot, batch, expdate, qty, inputdate, companyid, locationid, capacity")] Inventory inventory) { try { ViewBag.CompanyIDs = unitOfWork.CompanyRepository.Get().Where(c => c.billto == true && c.deleted != true).OrderBy(c => c.name); ViewBag.SKUs = unitOfWork.ItemRepository.Get().Where(i => i.deleted != true).OrderBy(i => i.sku); ViewData["locationid"] = EZDropDown.Locations(unitOfWork); ViewData["boxqty"] = EZDropDown.Qunatity(100, null); ViewData["itembox"] = EZDropDown.Qunatity(100, null); ViewBag.Barcode = Request["barcode"].ToString(); if (Request["hdnInventory"] == null) { ModelState.AddModelError("InventoryDetails", "Please provide Carton Q'ty, Items/Carton, Total Item Q'ty, Location and Use"); } if (ModelState.IsValid) { //TODO: Iterate the hdnInventory Values //TODO: Update the capacity within a loop string tmp = Request["hdnInventory"].ToString(); string[] aInvs = tmp.Split(','); foreach (string inv in aInvs) { string[] aInv = inv.Split(':'); //locationid:boxqty:itembox:qty:newCapacity InventoryDetail id = new InventoryDetail(); id.locationid = aInv[0]; id.lot = aInv[1]; id.boxqty = int.Parse(aInv[2]); id.itemperbox = int.Parse(aInv[3]); id.itemqty = int.Parse(aInv[4]); id.capacity = int.Parse(aInv[5]); inventory.InventoryDetails.Add(id); //////Location l = unitOfWork.LocationRepository.GetByID(aInv[0]); //////l.capacity = int.Parse(aInv[4]); //////unitOfWork.LocationRepository.Update(l); //////unitOfWork.Save(); } db.Inventories.Add(inventory); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } //ViewData["sku"] = EZDropDown.Products(unitOfWork); return(View(inventory)); }
public ViewResult Edit(int id) { //var order = unitOfWork.OrderRepository.GetByID(id); var order = unitOfWork.OrderRepository.Get(null, null, "OrderDetails").FirstOrDefault(o => o.id == id); var companies = unitOfWork.CompanyRepository.Get(); var inventories = unitOfWork.InventoryRepository.Get(); ViewData["BillTo"] = (from co in order.CompanyOrders.AsQueryable() join c in companies.AsQueryable() on co.companyid equals c.id where co.type == 1 select c.name).FirstOrDefault(); ViewData["ShipTo"] = (from co in order.CompanyOrders.AsQueryable() join c in companies.AsQueryable() on co.companyid equals c.id where co.type == 2 select c.name).FirstOrDefault(); int companyID = (from co in order.CompanyOrders.AsQueryable() join c in companies.AsQueryable() on co.companyid equals c.id where co.type == 1 select c.id).FirstOrDefault(); var groupOrderDetails = from t in ( from od in order.OrderDetails.AsQueryable() join inv in inventories.AsQueryable() on od.inventoryid equals inv.id select new { od, inv } ) group t by new { t.inv.sku, t.od.inventoryid } into grp select new { inventoryid = grp.Key.inventoryid, sku = grp.Key.sku, qty = grp.Sum(s => s.od.qty) }; ViewData["groupOrderDetails"] = groupOrderDetails.ToList(); //from od in order.OrderDetails.AsQueryable() // group od by new { od.Inventory.sku, od.inventoryid } into grp // select grp.Key.sku, grp.Sum(s => s.qty); ViewData["inventoryid"] = EZDropDown.InventoriesByCompany(unitOfWork, companyID); ViewData["statusid"] = EZDropDown.Statuses(unitOfWork, order.statusid); return(View(order)); }
public ViewResult Edit(int id) { var inventory = unitOfWork.InventoryRepository.Get(null, null, "InventoryDetails").FirstOrDefault(inv => inv.id == id); var product = (from p in unitOfWork.ItemRepository.Get().AsQueryable() where p.sku == inventory.sku select p).ToList().FirstOrDefault(); ViewBag.Barcocde = product.barcode; ViewData["companyid"] = EZDropDown.Companies(unitOfWork, inventory.companyid); ViewData["sku"] = EZDropDown.Products(unitOfWork, inventory.sku); //ViewData["locationid"] = EZDropDown.Locations(unitOfWork, inventory.locationid); //Location l = unitOfWork.LocationRepository.GetByID(inventory.locationid); ViewData["locationid"] = EZDropDown.Locations(unitOfWork); //ViewData["boxid"] = EZDropDown.Boxes(unitOfWork); ViewData["boxqty"] = EZDropDown.Qunatity(100, null); ViewData["quantity"] = EZDropDown.Qunatity(100, null); ViewData["itembox"] = EZDropDown.Qunatity(100, null); return(View(inventory)); }
public ActionResult Create(string barcode) { string sku = string.Empty; int companyID = 0; if (barcode != null) { var product = (from p in unitOfWork.ItemRepository.Get().AsQueryable() where p.barcode == barcode && p.deleted != true select p).ToList().FirstOrDefault(); ViewData["sku"] = EZDropDown.Products(unitOfWork, product.sku); ViewData["companyid"] = EZDropDown.Companies(unitOfWork, (int)product.companyid); } else { ViewData["sku"] = EZDropDown.Products(unitOfWork, null); ViewData["companyid"] = EZDropDown.Companies(unitOfWork, null); } ViewData["locationid"] = EZDropDown.Locations(unitOfWork); ViewData["boxqty"] = EZDropDown.Qunatity(100, null); ViewData["itembox"] = EZDropDown.Qunatity(100, null); ViewBag.Barcode = barcode; return(View()); }
public ActionResult Create([Bind(Include = "date, statusid, rate, deleted")] Order order) { try { ViewData["billtoid"] = EZDropDown.Companies(unitOfWork); if (Request["billtoid"].ToString() == "") { ModelState.AddModelError("CompanyOrders", "Required"); } if (Request["shiptoid"] != null && Request["shiptoid"].ToString() == "") { ModelState.AddModelError("CompanyOrders", "Required"); } //if (Request["hdnInventory"] == null) //{ // //} if ((Request["inventoryid"] == null) || (Request["qty"] == null) || (Request["inventoryid"] != null && Request["inventoryid"].ToString() == "") || (Request["qty"] != null && Request["qty"].ToString() == "")) { ModelState.AddModelError("OrderDetails", "Inventory and Quantity are required"); } if (ModelState.IsValid) { int billToID = int.Parse(Request["billtoid"].ToString()); int shipToID = int.Parse(Request["shiptoid"].ToString()); CompanyOrder co = new CompanyOrder(); co.type = 1;//BillTo co.companyid = billToID; order.CompanyOrders.Add(co); co = new CompanyOrder(); co.type = 2;//ShipTo co.companyid = shipToID; order.CompanyOrders.Add(co); int inventoryID = int.Parse(Request["inventoryid"].ToString()); int itemTotalQty = int.Parse(Request["qty"].ToString()); int boxqty = 0; int itemQtyLocation = 0; var inventoryDetails = unitOfWork.InventoryDetailRepository.Get().Where(id => id.inventoryid == inventoryID).ToList(); foreach (InventoryDetail id in inventoryDetails) { int quantity = (int)id.boxqty * (int)id.itemperbox + (int)id.itemqty; if (quantity < itemTotalQty) //Items are stored in multiple locations { itemQtyLocation = quantity; //Partial quantity in a location } else { itemQtyLocation = itemTotalQty;//The entire quantity } boxqty = (int)Math.Ceiling((decimal)(itemQtyLocation) / (int)(id.itemperbox)); OrderDetail od = new OrderDetail(); od.inventoryid = inventoryID; od.qty = itemQtyLocation; od.boxqty = boxqty; od.locationid = id.locationid; order.OrderDetails.Add(od); if (quantity < itemTotalQty)//More items to ship so get it from a different location { itemTotalQty -= quantity; } else { break; } } //TO DO: Subtract item and box quantity! //db.Entry(inventoryDetail).State = EntityState.Modified; //inventoryDetail.boxqty -= boxqty; //inventoryDetail.itemqty -= itemqty; if (Request["hdnInventory"] != null) { string tmp = Request["hdnInventory"].ToString(); string[] aInvs = tmp.Split(','); foreach (string inv in aInvs) { string[] aInv = inv.Split(':'); //od = new OrderDetail(); //od.inventoryid = int.Parse(aInv[0]); //od.qty = int.Parse(aInv[1]); //boxqty = (int)Math.Ceiling(decimal.Parse(aInv[1]) / (int)(inventoryDetail.itemperbox)); //od.boxqty = boxqty; inventoryID = int.Parse(aInv[0]); itemTotalQty = int.Parse(aInv[1]); inventoryDetails = unitOfWork.InventoryDetailRepository.Get().Where(id => id.inventoryid == inventoryID).ToList(); foreach (InventoryDetail id in inventoryDetails) { int quantity = (int)id.boxqty * (int)id.itemperbox + (int)id.itemqty; if (quantity < itemTotalQty) //Items are stored in multiple locations { itemQtyLocation = quantity; //Partial quantity in a location } else { itemQtyLocation = itemTotalQty;//The entire quantity } boxqty = (int)Math.Ceiling((decimal)(itemQtyLocation) / (int)(id.itemperbox)); OrderDetail od = new OrderDetail(); od.inventoryid = inventoryID; od.qty = itemQtyLocation; od.boxqty = boxqty; od.locationid = id.locationid; order.OrderDetails.Add(od); if (quantity < itemTotalQty)//More items to ship so get it from a different location { itemTotalQty -= quantity; } else { break; } } //order.OrderDetails.Add(od); } } db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(View(order)); }
public ActionResult Create() { ViewData["billtoid"] = EZDropDown.Companies(unitOfWork); //ViewData["inventoryid"] = EZDropDown.Inventories(unitOfWork); return(View()); }
public ActionResult Edit([Bind(Include = "id, sku, lot, batch, expdate, qty, inputdate, companyid, locationid, capacity")] Inventory inventory) { try { ViewData["companyid"] = EZDropDown.Companies(unitOfWork, inventory.companyid); ViewData["sku"] = EZDropDown.Products(unitOfWork, inventory.sku); ViewData["locationid"] = EZDropDown.Locations(unitOfWork); ViewData["boxqty"] = EZDropDown.Qunatity(100, null); ViewData["itembox"] = EZDropDown.Qunatity(100, null); if (Request["companyid"] == "") { ModelState.AddModelError("companyid", "Required"); } if (Request["sku"] == "") { ModelState.AddModelError("sku", "Required"); } if (Request["hdnInventory"] == null) { ModelState.AddModelError("InventoryDetails", "Please provide Carton Q'ty, Items/Carton, Total Item Q'ty, Location and Use"); } if (ModelState.IsValid) { foreach (InventoryDetail id in db.InventoryDetails.Where(id => id.inventoryid == inventory.id)) { db.Entry(id).State = EntityState.Deleted; //Location l = unitOfWork.LocationRepository.GetByID(id.locationid); //l.capacity = int.Parse(aInv[4]); //unitOfWork.LocationRepository.Update(l); //unitOfWork.Save(); } db.Entry(inventory).State = EntityState.Modified; string tmp = Request["hdnInventory"].ToString(); string[] aInvs = tmp.Split(','); foreach (string inv in aInvs) { string[] aInv = inv.Split(':'); //locationid:qty:boxid:quantity:newCapacity //locationid:boxqty:itembox:qty:newCapacity InventoryDetail id = new InventoryDetail(); id.locationid = aInv[0]; id.lot = aInv[1]; id.boxqty = int.Parse(aInv[2]); id.itemperbox = int.Parse(aInv[3]); id.itemqty = int.Parse(aInv[4]); id.capacity = int.Parse(aInv[5]); inventory.InventoryDetails.Add(id); //Location l = unitOfWork.LocationRepository.GetByID(aInv[0]); //l.capacity = int.Parse(aInv[4]); //unitOfWork.LocationRepository.Update(l); //unitOfWork.Save(); } db.SaveChanges(); //var formerLocationID = Request["formerLocationID"].ToString(); //int formerCapacity = Convert.ToInt32(Request["formerCapacity"].ToString()); //unitOfWork.InventoryRepository.Update(inventory); //unitOfWork.Save(); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name after DataException and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } ViewBag.sku = EZDropDown.Products(unitOfWork, inventory.sku); return(View(inventory)); }