public APIJsonResult Delete(int roleID) { var roleBLL = new TRoleBLL(); try { roleBLL.Delete(roleID); }catch (ValidationException ex) { return(Failed(ex.Message)); } roleBLL.SaveChanges(); return(Success()); }
// GET api/values/5 public APIJsonResult Add(RoleModel roleModel) { roleModel.Name = roleModel.Name.Trim(); var roleBLL = new TRoleBLL(); var role = new TRole(); UtilHelper.CopyProperties(roleModel, role); AddCreateInfo(role); try { roleBLL.Add(role); } catch (ValidationException ex) { return(Failed(ex.Message)); } roleBLL.SaveChanges(); if (roleModel.PermissionIDList != null && roleModel.PermissionIDList.Count > 0) { var rolePermissionBLL = new TRolePermissionBLL(); foreach (var permissionID in roleModel.PermissionIDList) { var rolePermission = new TRolePermission() { PermissionID = permissionID, RoleID = role.ID }; AddCreateInfo(rolePermission); rolePermissionBLL.Add(rolePermission); } rolePermissionBLL.SaveChanges(); } return(Success()); }
public APIJsonResult Edit(RoleModel roleModel) { var roleBLL = new TRoleBLL(); var role = new TRole(); UtilHelper.CopyProperties(roleModel, role); AddUpdateInfo(role); try { roleBLL.Edit(role, new string[] { "Name" }); } catch (ValidationException ex) { return(Failed(ex.Message)); } roleBLL.SaveChanges(); var rolePermissionBLL = new TRolePermissionBLL(); rolePermissionBLL.Delete(c => c.RoleID == role.ID); if (roleModel.PermissionIDList != null && roleModel.PermissionIDList.Count > 0) { foreach (var permissionID in roleModel.PermissionIDList) { var rolePermission = new TRolePermission() { PermissionID = permissionID, RoleID = role.ID }; AddCreateInfo(rolePermission); rolePermissionBLL.Add(rolePermission); } } rolePermissionBLL.SaveChanges(); return(Success()); }