/// <summary> /// Creates a new UserRole. /// </summary> /// <param name="role"></param> public void Create(UserRole role) { ThrowIfNull(role); role.IsEditable = true; ValidateAndThrow(role, _userRoleValidator); Context.UserRoles.Add(role); Context.SaveChanges(); }
/// <summary> /// Updates a UserRole. /// Makes sure the db version is editable. /// </summary> /// <param name="role"></param> public void Update(UserRole role) { ThrowIfNull(role); // only pulling dbRole to make sure it is editable, otherwise could just attach... var dbRole = Context.UserRoles.Single(ur => ur.Id == role.Id); dbRole.Name = role.Name; dbRole.Description = role.Description; ValidateAndThrow(dbRole, _userRoleValidator); // ensures editable Context.SetEntityState(dbRole, EntityState.Modified); Context.SaveChanges(); }
public ActionResult Add(UserRole model) { Utility.ReturnData<string> returnData = new Utility.ReturnData<string>(); model.Addtime = DateTime.Now; model.AddUserBasicID = LoginUser.UserBasicID; model.EnterpriseID = LoginUser.UserBasic.EnterpriseID; returnData = bll.AddOrUpdateUserRole(model); if (returnData.Message=="添加成功!") { return Content(returnData.Message); } else { return Content(returnData.Message); } }
public void Add(UserRole pUserRole) { _arrayInternal.Add(pUserRole); }
/// <summary> /// Checks that a UserRole name is unique before saving. /// </summary> /// <param name="role"></param> /// <param name="name"></param> /// <returns>Returns a bool indicating uniqueness.</returns> public bool BeAUniqueUserRoleName(UserRole role, string name) { return(!Context.UserRoles.Any(r => r.Name == name && r.Id != role.Id)); }