/// <summary> /// 修改 /// </summary> /// <param name="model"></param> /// <param name="sid"></param> public static void UpdateModel(Base_Dept model, int sid) { using (DBContext dbContext = new DBContext()) { Base_Dept editmodel = dbContext.Base_Dept.Where(u => u.id == sid).FirstOrDefault(); if (editmodel == null) { return;//空 } editmodel.DeptName = model.DeptName; editmodel.Remark = model.Remark; //提交修改 dbContext.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="sid"></param> /// <returns></returns> public static string GetDeptName(int?sid) { string returnFlag = ""; using (DBContext dbContext = new DBContext()) { //if (sid == null) //{ // return ""; //} Base_Dept model = dbContext.Base_Dept.Where(u => u.id == sid).FirstOrDefault(); if (model != null) { returnFlag = model.DeptName; } } return(returnFlag); }
/// <summary> /// 删除 /// </summary> /// <param name="sid"></param> /// <returns></returns> public static bool DeleteModel(int sid) { bool returnFlag = false; using (DBContext dbContext = new DBContext()) { Base_Dept model = dbContext.Base_Dept.Where(u => u.id == sid).FirstOrDefault(); if (model != null) { dbContext.Base_Dept.Remove(model); dbContext.SaveChanges(); returnFlag = true; } } return(returnFlag); }
/// <summary> /// 新增 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool AddModel(Base_Dept model) { bool returnFlag = false; using (DBContext dbContext = new DBContext()) { Base_Dept NewModel = new Base_Dept() { DeptName = model.DeptName, Remark = model.Remark }; //增加 dbContext.Base_Dept.Add(NewModel); dbContext.SaveChanges(); returnFlag = true; } return(returnFlag); }