/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(GroupRoleViewModel model) { var entity = model.ToEntity(); this._GroupRolesRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">GroupRole view model</param> public void ThrowExceptionIfExist(GroupRoleViewModel model) { ConditionFilter <GroupRole, long> condition = new ConditionFilter <GroupRole, long> { Query = (entity => entity.Name == model.Name && entity.Id != model.Id) }; var existEntity = this._GroupRolesRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException(); } }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public GroupRoleViewModel Update(GroupRoleViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._GroupRolesRepository.Update(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public ActionResult SetRole(int?id, GroupRoleViewModel groupRoleViewModel) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IQueryable <Role> existRole = _roleService.GetAll().Where(x => x.GroupId == id); _roleService.RemoveRange(existRole); foreach (int item in groupRoleViewModel.DepartmentId) { _roleService.Add(new Role { GroupId = id.Value, Name = item.ToString() }); } TempData["Status"] = "Cài đặt quyền thành công!"; return(RedirectToAction("Index")); }