public RedirectToRouteResult EditItem(String[] suppliers, String[] desc, String[] status, string[] reorderlvl, string[] reorderqty) { using (SSISdbEntities e = new SSISdbEntities()) { try { string itemCode = Session["MaintenanceItemCode"].ToString(); Item item = e.Items.Where(x => x.ItemCode == itemCode).FirstOrDefault(); DAL.ItemsRepositoryImpl dal = new DAL.ItemsRepositoryImpl(e); if (status != null) { if (status[0].ToLower() == "true") { item.Active = 1; } else { item.Active = 0; } } item.ReOrderLevel = Convert.ToInt32(reorderlvl[0]); item.ReOrderQuantity = Convert.ToInt32(reorderqty[0]); item.Description = desc[0]; item.Supplier1 = suppliers[0]; item.Supplier2 = suppliers[1]; item.Supplier3 = suppliers[2]; dal.UpdateItem(item); e.SaveChanges(); Session["MaintenanceItemsPage"] = "1"; return(RedirectToAction("Maintenance", "Store")); } catch (FormatException fe) { Debug.WriteLine(fe.Message); }catch (Exception ex) { Debug.WriteLine(ex.Message); } return(null); } }
public RedirectToRouteResult AddNewItem(Item item) { using (SSISdbEntities e = new SSISdbEntities()) { string category = Request.Form["SelectItemCategory"].ToString(); string UoM = Request.Form["SelectItemUOM"].ToString(); string supplier1 = Request.Form["SelectSupplier1"].ToString(); string supplier2 = Request.Form["SelectSupplier2"].ToString(); string supplier3 = Request.Form["SelectSupplier3"].ToString(); string itemFirstChar = "Z"; int countWithItemFirstChar = e.Items.Where(x => x.ItemCode.Substring(0, 1).ToUpper() == itemFirstChar).Count() + 1; switch (countWithItemFirstChar.ToString().Length) { case 1: item.ItemCode = itemFirstChar + "00" + countWithItemFirstChar; break; case 2: item.ItemCode = itemFirstChar + "0" + countWithItemFirstChar; break; case 3: item.ItemCode = itemFirstChar + countWithItemFirstChar; break; } item.CategoryID = category; item.UoM = UoM; item.Supplier1 = supplier1; item.Supplier2 = supplier2; item.Supplier3 = supplier3; item.Active = 1; item.AvgUnitCost = 0; DAL.ItemsRepositoryImpl dal = new DAL.ItemsRepositoryImpl(e); dal.InsertItem(item); e.SaveChanges(); return(RedirectToAction("Maintenance", "Store")); } }