public ActionResult EditModel(computer_brand brand) { if (brand == null) { return(RedirectToAction("Index")); } using (frycz_pcdbEntities entities = new frycz_pcdbEntities()) { computer_brand cb = entities.computer_brand.FirstOrDefault(e => e.idcumputer_brand == brand.idcumputer_brand); return(View("EditModel", cb)); } }
public ActionResult SaveAdd(computer_brand brand) { if (!Validator.validModel(brand)) { ModelState.AddModelError("exist", "Computer model is invalid or inuse."); return(View("AddModel", brand)); } using (frycz_pcdbEntities entities = new frycz_pcdbEntities()) { entities.computer_brand.Add(brand); Logger.logModel(brand, "Add", User); entities.SaveChanges(); return(RedirectToAction("Index", "ComputerModel")); } }
public ActionResult Delete(computer_brand brand) { if (brand == null) { return(RedirectToAction("Index")); } using (frycz_pcdbEntities entities = new frycz_pcdbEntities()) { computer_brand b = entities.computer_brand.FirstOrDefault(e => e.idcumputer_brand == brand.idcumputer_brand); entities.computer_brand.Remove(b); Logger.logModel(b, "Delete", User); entities.SaveChanges(); return(RedirectToAction("Index", "ComputerModel")); } }
public static bool validModel(computer_brand brand) { if (brand == null) { return(false); } if (brand.model == null || brand.model.Equals(String.Empty) || brand.maker == null || brand.maker.Equals(String.Empty)) { return(false); } using (frycz_pcdbEntities entities = new frycz_pcdbEntities()) { int count = entities.computer_brand.Count(t => t.maker.Equals(brand.maker) && t.model.Equals(brand.model)); return(count <= 0); } }
public ActionResult SaveEdit(computer_brand brand) { if (!Validator.validModel(brand)) { ModelState.AddModelError("exist", "Computer model is invalid or inuse."); return(View("EditModel", brand)); } using (frycz_pcdbEntities entities = new frycz_pcdbEntities()) { computer_brand b = entities.computer_brand.FirstOrDefault(e => e.idcumputer_brand == brand.idcumputer_brand); b.maker = brand.maker; b.model = brand.model; Logger.logModel(brand, "Edit", User); entities.SaveChanges(); return(RedirectToAction("Index", "ComputerModel")); } }
public string AddAjax(string model, string maker) { computer_brand c = new computer_brand(); c.maker = maker; c.model = model; if (!Validator.validModel(c)) { return(null); } using (frycz_pcdbEntities entities = new frycz_pcdbEntities()) { entities.computer_brand.Add(c); Logger.logModel(c, "Add", User); entities.SaveChanges(); return("{\"msg\":\"success\"}"); } }
public static void logModel(computer_brand brand, string operationMessage, IPrincipal user) { logToDB(operationMessage + " computer model: " + brand.maker + " " + brand.model, user); }