/// <summary> /// 添加新班级 /// </summary> ///<returns>成功返回true</returns> public static bool AddClass(Classes model) { try { using (var db = new SEMSDBContext()) { /*var classes = new Classes() { class_grade = model.class_grade, class_id = model.class_id, class_small_id = model.class_small_id };*/ db.Classes.Add(model); db.SaveChanges(); } return true; } catch (DbEntityValidationException e) { Debug.WriteLine(e.Message); return false; } catch { return false; } }
public ActionResult Edit(string id, string smallid, string grade) { ViewBag.ID = id; ViewBag.SmallID = smallid; Classes model = new Classes() { class_id = id, class_small_id = smallid, class_grade = grade }; return View(model); }
public ActionResult Edit(string id,string smallid,Classes ChangeModel) { if (BLL.ClassesBS.ModifyClass(id,smallid,ChangeModel)) { return RedirectToAction("Index", "Classes"); } else ModelState.AddModelError("", "修改失败!"); //修改失败 return View(ChangeModel); //return new EmptyResult(); }
/// <summary> /// 修改班级信息 /// </summary> ///<returns>成功返回true</returns> public static bool ModifyClass(string main_id, string small_id, Classes newModel) { try { using (var db = new SEMSDBContext()) { Classes toChange = db.Classes.Find(main_id, small_id); toChange.class_grade = newModel.class_grade; db.SaveChanges(); } return true; } catch { return false; } }