Пример #1
0
        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));
        }
Пример #2
0
        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());
        }
Пример #3
0
        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));
        }