/// <summary> /// 验证用户名是否改变 /// </summary> /// <param name="name">用户名</param> /// <returns></returns> public bool CheckName(SysPerson sysPerson) { using (SysEntities dbCheckName = new SysEntities()) { SysPerson person = dbCheckName.SysPerson.FirstOrDefault(f => f.Id == sysPerson.Id); if (person != null) { if (sysPerson.Name == person.Name) { return false;//没有修改用户名 } else { return CheckName(sysPerson.Name); } } } return true; }
/// <summary> /// Deprecated Method for adding a new object to the SysPerson EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSysPerson(SysPerson sysPerson) { base.AddObject("SysPerson", sysPerson); }
/// <summary> /// Create a new SysPerson object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="password">Initial value of the Password property.</param> public static SysPerson CreateSysPerson(global::System.String id, global::System.String name, global::System.String password) { SysPerson sysPerson = new SysPerson(); sysPerson.Id = id; sysPerson.Name = name; sysPerson.Password = password; return sysPerson; }
/// <summary> /// 创建一个角色 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个角色</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysRole entity) { int count = 1; foreach (string item in entity.SysPersonId.GetIdSort()) { SysPerson sys = new SysPerson { Id = item }; db.SysPerson.Attach(sys); entity.SysPerson.Add(sys); count++; } repository.Create(db, entity); if (count == repository.Save(db)) { return true; } else { validationErrors.Add("创建出错了"); } return false; }
/// <summary> /// 编辑一个角色 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据上下文</param> /// <param name="entity">一个角色</param> /// <returns>是否编辑成功</returns> public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysRole entity) { /* * 不操作 原有 现有 * 增加 原没 现有 * 删除 原有 现没 */ if (entity == null) { return false; } int count = 1; SysRole editEntity = repository.Edit(db, entity); List<string> addSysPersonId = new List<string>(); List<string> deleteSysPersonId = new List<string>(); DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(), ref addSysPersonId, ref deleteSysPersonId); if (addSysPersonId != null && addSysPersonId.Count() > 0) { foreach (var item in addSysPersonId) { SysPerson sys = new SysPerson { Id = item }; db.SysPerson.Attach(sys); editEntity.SysPerson.Add(sys); count++; } } if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0) { List<SysPerson> listEntity = new List<SysPerson>(); foreach (var item in deleteSysPersonId) { SysPerson sys = new SysPerson { Id = item }; listEntity.Add(sys); db.SysPerson.Attach(sys); } foreach (SysPerson item in listEntity) { editEntity.SysPerson.Remove(item);//查询数据库 count++; } } if (count == repository.Save(db)) { return true; } else { validationErrors.Add("编辑角色出错了"); } return false; }
public ActionResult Edit(string id, SysPerson entity) { if (entity != null && ModelState.IsValid) { //数据校验 string currentPerson = GetCurrentPerson(); entity.UpdateTime = DateTime.Now; entity.UpdatePerson = currentPerson; //加密 entity.Password = EncryptAndDecrypte.EncryptString(entity.Password); entity.SurePassword = entity.Password; string returnValue = string.Empty; if (m_BLL.Edit(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",人员信息的Id为" + id, "人员" );//写入日志 return Json(Suggestion.UpdateSucceed); //提示更新成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return true; }); } LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",人员信息的Id为" + id + "," + returnValue, "人员" );//写入日志 return Json(Suggestion.UpdateFail + returnValue); //提示更新失败 } } return Json(Suggestion.UpdateFail + "请核对输入的数据的格式"); //提示输入的数据的格式不对 }
public ActionResult Create(SysPerson entity) { if (entity != null && ModelState.IsValid) { string currentPerson = GetCurrentPerson(); entity.CreateTime = DateTime.Now; entity.CreatePerson = currentPerson; //加密 entity.Password = EncryptAndDecrypte.EncryptString(entity.Password); entity.SurePassword = entity.Password; entity.Id = Result.GetNewId(); string returnValue = string.Empty; if (m_BLL.Create(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",人员的信息的Id为" + entity.Id, "人员" );//写入日志 return Json(Suggestion.InsertSucceed); } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return true; }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",人员的信息," + returnValue, "人员" );//写入日志 return Json(Suggestion.InsertFail + returnValue); //提示插入失败 } } return Json(Suggestion.InsertFail + ",请核对输入的数据的格式"); //提示输入的数据的格式不对 }
/// <summary> /// 编辑一个人员 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个人员</param> /// <returns>是否编辑成功</returns> public bool Edit(ref ValidationErrors validationErrors, SysPerson entity) { try { using (TransactionScope transactionScope = new TransactionScope()) { if (Edit(ref validationErrors, db, entity)) { transactionScope.Complete(); return true; } else { Transaction.Current.Rollback(); } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return false; }
/// <summary> /// 创建一个人员 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个人员</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity) { int count = 1; if (CheckName(entity.Name)) { validationErrors.Add("用户名已被占用,请换一个新的用户名"); return false; } foreach (string item in entity.SysRoleId.GetIdSort()) { SysRole sys = new SysRole { Id = item }; db.SysRole.Attach(sys); entity.SysRole.Add(sys); count++; } repository.Create(db, entity); if (count == repository.Save(db)) { return true; } else { validationErrors.Add("创建出错了"); } return false; }