public ActionResult MaintainStockType(Stock_Type stock_Type, string button) { if (button == "Save") { try { Stock_Type Stock_Type = db.Stock_Type.Find(stock_Type.Stock_Type_ID); if (Stock_Type == null) { return(HttpNotFound()); } else { db.Entry(Stock_Type).CurrentValues.SetValues(stock_Type); db.SaveChanges(); } } catch (Exception e) { return(RedirectToAction("MaintainStockType", "Stock")); } } else if (button == "Cancel") { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public ActionResult MaintainStockType(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Stock_Type stock_Type = db.Stock_Type.Find(id); if (stock_Type == null) { return(HttpNotFound()); } return(View(stock_Type)); }
public static void DeleteStockType(int stocktypeID) { using (ctaDBEntities entities = new ctaDBEntities()) { Stock_Type st = entities.Stock_Type.Where(s => s.Id == stocktypeID).FirstOrDefault(); if (st != null) { entities.Stock_Type.Remove(st); entities.SaveChanges(); } if (!(entities.Database.Connection.State == ConnectionState.Closed)) { entities.Database.Connection.Close(); } } }
public static void CreateStockType(StockTypeModel stockTypeModel) { using (ctaDBEntities entities = new ctaDBEntities()) { Stock_Type st = new Stock_Type() { name = stockTypeModel.name }; entities.Stock_Type.Add(st); entities.SaveChanges(); if (!(entities.Database.Connection.State == ConnectionState.Closed)) { entities.Database.Connection.Close(); } } }
public ActionResult AddStockType(Stock_Type stock_type, string button) { ViewBag.errorMessage = ""; if (button == "Save") { try { List <Stock_Type> stock_types = new List <Stock_Type>(); stock_types = db.Stock_Type.ToList(); if (stock_types.Count != 0) { int count = 0; foreach (var item in stock_types) { if (item.Stock_Type_Name == stock_type.Stock_Type_Name && item.Stock_Type_Description == stock_type.Stock_Type_Description) { count++; ViewBag.errorMessage = "There is a duplicate Stock Type Already"; return(View()); } } if (count == 0) { db.Stock_Type.Add(stock_type); db.SaveChanges(); } } else { db.Stock_Type.Add(stock_type); db.SaveChanges(); } } catch (Exception e) { ViewBag.errorMessage = "There was an Error with network please try again: " + e.Message; return(View()); } } else if (button == "Cancel") { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public static void UpdateStockType(StockTypeModel stockTypeModel) { using (ctaDBEntities entities = new ctaDBEntities()) { Stock_Type st = entities.Stock_Type.Where(s => s.Id == stockTypeModel.Id).FirstOrDefault(); if (st != null) { st.name = stockTypeModel.name; entities.SaveChanges(); } if (!(entities.Database.Connection.State == ConnectionState.Closed)) { entities.Database.Connection.Close(); } } }