public int MarkDelete(string id) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(id); if (!isExist) { throw new PushToUserException("Current api permission item is not exist"); } try { dbContext.DBTransaction.Begin(); dbContext.Update <Role_Permission>(rp => new { rp.DelFlag }, new Role_Permission { DelFlag = 1 }).Where(rp => rp.PermissionId.Equals(id)).Done(); int res = commonService.MarkDeleteById(id); dbContext.DBTransaction.Commit(); return(res); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public int MarkDelete(string id) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <AdminUser> commonService = new CommonService <AdminUser>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(id); if (!isExist) { throw new PushToUserException("Current dictionary item is not exist"); } try { dbContext.DBTransaction.Begin(); dbContext.Update <AdminUserInfo>(a => new { a.DelFlag }, new AdminUserInfo { DelFlag = 1 }).Where(a => a.AdminUserId.Equals(id)).Done(); int res = commonService.MarkDeleteById(id); dbContext.DBTransaction.Commit(); return(res); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public void EditOne(Permission_AddEditDTO editOne, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id); if (!isExist) { throw new PushToUserException("Current api permission item is not exist"); } bool hasExist = commonService.WhereNoMarkDeleted().Where(p => 0 == p.DelFlag && p.Id != editOne.Id && p.ApiUrl.Equals(editOne.ApiUrl)).Any(); if (hasExist) { throw new PushToUserException($"A api permission item with the same api url '{editOne.ApiUrl}' already exists"); } Permission updateOne = CoffeeMapper <Permission_AddEditDTO, Permission> .AutoMap(editOne, (_out, _in) => { _out.Updater = updater; _out.UpdateTime = DateTime.Now; }); dbContext.Update <Permission>(p => new { p.Name, p.ApiType, p.ApiUrl, p.ApiMethod, p.RemarkInfo, p.SortNumber, p.Updater, p.UpdateTime }, updateOne) .Where(d => d.Id.Equals(updateOne.Id)).Done(); } }
public void EditOne(Department_AddEditDTO editOne, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Department> commonService = new CommonService <Department>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id); if (!isExist) { throw new PushToUserException("Current Department item is not exist"); } bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(editOne.Name) && d.Id != editOne.Id).Any(); if (hasExist) { throw new PushToUserException($"A Department item with the same name '{editOne.Name}' already exists"); } Department updateOne = CoffeeMapper <Department_AddEditDTO, Department> .AutoMap(editOne, (_out, _in) => { _out.Updater = updater; _out.UpdateTime = DateTime.Now; }); dbContext.Update <Department>(d => new { d.Name, d.ParentId, d.RemarkInfo, d.SortNumber, d.Updater, d.UpdateTime }, updateOne) .Where(d => d.Id.Equals(updateOne.Id)).Done(); } }
public void EditOne(Account_AddEditDTO editOne, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <AdminUser> commonService = new CommonService <AdminUser>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id); if (!isExist) { throw new PushToUserException("Current account item is not exist"); } bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Account.Equals(editOne.Account) && d.Id != editOne.Id).Any(); if (hasExist) { throw new PushToUserException($"A admin user item with the same account '{editOne.Account}' already exists"); } try { dbContext.DBTransaction.Begin(); AdminUser updateAdminUserOne = CoffeeMapper <Account_AddEditDTO, AdminUser> .AutoMap(editOne, (_out, _in) => { _out.Updater = updater; _out.UpdateTime = DateTime.Now; }); var matchAdminUserInfo = dbContext.Queryable <AdminUserInfo>().Select().Where(a => a.AdminUserId.Equals(editOne.Id)).ToList(); if (matchAdminUserInfo.Count != 1) { throw new Exception($"TABLE 'IDSBG_ECARD.B_ADMIN_USER' record which AdminUserId = '{editOne.Id}' is not only one or not exist"); } AdminUserInfo updateAdminUserInfoOne = matchAdminUserInfo[0]; updateAdminUserInfoOne.Name = editOne.Name; updateAdminUserInfoOne.RemarkInfo = editOne.Remarks; updateAdminUserInfoOne.Updater = updater; updateAdminUserInfoOne.UpdateTime = DateTime.Now; dbContext.Update <AdminUserInfo>(updateAdminUserInfoOne); dbContext.Update <AdminUser>(a => new { a.Account, a.RemarkInfo, a.Updater, a.UpdateTime }, updateAdminUserOne) .Where(a => a.Id.Equals(editOne.Id)).Done(); dbContext.DBTransaction.Commit(); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public void UpdateRolesForAccount(string accountId, string[] roleIds, string creater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <AdminUser> commonService = new CommonService <AdminUser>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(accountId); if (!isExist) { throw new PushToUserException("Current account item is not exist"); } try { dbContext.DBTransaction.Begin(); dbContext.Update <AdminUser_Role>(ar => new { ar.DelFlag }, new AdminUser_Role { DelFlag = 1 }) .Where(ar => ar.AdminUserId.Equals(accountId)).Done(); foreach (string roleId in roleIds) { isExist = dbContext.Queryable <Role>().Where(r => r.DelFlag == 0 && r.Id == roleId).Any(); if (!isExist) { throw new PushToUserException("the role you choosed is not exist"); } dbContext.Add(new AdminUser_Role { Id = Utils.GetGuidStr(), AdminUserId = accountId, RoleId = roleId, Creater = creater, Updater = creater }); } dbContext.DBTransaction.Commit(); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public int MarkDelete(string id) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Dictionary> commonService = new CommonService <Dictionary>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(id); if (!isExist) { throw new PushToUserException("Current dictionary item is not exist"); } return(commonService.MarkDeleteById(id)); } }
public int MarkDelete(string id) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Menu> commonService = new CommonService <Menu>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(id); if (!isExist) { throw new PushToUserException("Current menu item is not exist"); } bool hasChildren = commonService.GetAllNoMarkDeleted().Where(m => m.ParentId == id).Any(); if (hasChildren) { throw new PushToUserException("Current menu item has children, can not be deleted"); } try { dbContext.DBTransaction.Begin(); var perm = dbContext.Queryable <Permission>().Select().Where(p => p.MenuId == id).ToOne(); if (null != perm) { dbContext.Update <Permission>(rp => new { rp.DelFlag }, new Permission { DelFlag = 1 }).Where(p => p.MenuId.Equals(id)).Done(); dbContext.Update <Role_Permission>(rp => new { rp.DelFlag }, new Role_Permission { DelFlag = 1 }).Where(rp => rp.PermissionId == perm.Id).Done(); } int res = commonService.MarkDeleteById(id); dbContext.DBTransaction.Commit(); return(res); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public void EditMenuForRole(string roleId, string[] hasMenuIds, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Role> commonService = new CommonService <Role>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(roleId); if (!isExist) { throw new PushToUserException("Current role item is not exist"); } try { dbContext.DBTransaction.Begin(); dbContext.ExecuteSql(RoleService_SQL.MarkDeleteAllMenuPermsOfRole, roleId); foreach (string menuId in hasMenuIds) { var permItem = dbContext.Queryable <Permission>().Select(p => new { p.Id }).Where(p => p.DelFlag == 0 && p.MenuId == menuId).ToOne(); if (null == permItem) { throw new PushToUserException("menu item is not exist"); } dbContext.Add(new Role_Permission { Id = Utils.GetGuidStr(), RoleId = roleId, PermissionId = permItem.Id, Creater = updater, Updater = updater }); } dbContext.DBTransaction.Commit(); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public void EditOne(Menu_AddEditDTO editOne, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Menu> commonService = new CommonService <Menu>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id); if (!isExist) { throw new PushToUserException("Current menu item is not exist"); } bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Type != editOne.Type && d.Id == editOne.Id).Any(); if (hasExist) { throw new PushToUserException($"the type of Menu item is not allow to change"); } hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(editOne.Name) && d.Id != editOne.Id).Any(); if (hasExist) { throw new PushToUserException($"A menu item with the same name '{editOne.Name}' already exists"); } if (!string.IsNullOrEmpty(editOne.PagePath)) { hasExist = commonService.WhereNoMarkDeleted().Where(d => d.PagePath.Equals(editOne.PagePath) && d.Id != editOne.Id).Any(); if (hasExist) { throw new PushToUserException($"A menu item with the same page path '{editOne.PagePath}' already exists"); } } Menu updateOne = CoffeeMapper <Menu_AddEditDTO, Menu> .AutoMap(editOne, (_out, _in) => { _out.Updater = updater; _out.UpdateTime = DateTime.Now; }); dbContext.Update <Menu>(d => new { d.Name, d.PagePath, d.ParentId, d.Icon, d.Type, d.RemarkInfo, d.SortNumber, d.Updater, d.UpdateTime }, updateOne) .Where(d => d.Id.Equals(updateOne.Id)).Done(); } }
public int MarkDelete(string id) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Department> commonService = new CommonService <Department>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(id); if (!isExist) { throw new PushToUserException("Current Department item is not exist"); } bool hasChildren = commonService.GetAllNoMarkDeleted().Where(m => m.ParentId == id).Any(); if (hasChildren) { throw new PushToUserException("Current Department item has children, can not be deleted"); } try { dbContext.DBTransaction.Begin(); dbContext.Update <AdminUser_Department>(ad => new { ad.DelFlag }, new AdminUser_Department { DelFlag = 1 }).Where(rp => rp.DepartmentId == id).Done(); int res = commonService.MarkDeleteById(id); dbContext.DBTransaction.Commit(); return(res); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public void EditApiPermForRole(string roleId, string[] hasApiPermissionIds, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Role> commonService = new CommonService <Role>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(roleId); if (!isExist) { throw new PushToUserException("Current role item is not exist"); } try { dbContext.DBTransaction.Begin(); dbContext.ExecuteSql(RoleService_SQL.MarkDeleteAllApiPermsOfRole, roleId); foreach (string apiPermissionId in hasApiPermissionIds) { dbContext.Add(new Role_Permission { Id = Utils.GetGuidStr(), RoleId = roleId, PermissionId = apiPermissionId, Creater = updater, Updater = updater }); } dbContext.DBTransaction.Commit(); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }