public Account_ShowDTO MatchLogin(string account, string password) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <AdminUser> commonService = new CommonService <AdminUser>(dbContext); var matchAccount = commonService.WhereNoMarkDeleted() .Select(a => new { a.Id }) .Where(a => a.Account.Equals(account) && a.PasswordHash.Equals(password)) .ToList(); if (null == matchAccount) { throw new PushToUserException("the entered account or password is incorrect"); } else if (1 == matchAccount.Count) { var loginUser = dbContext.Queryable(AccountService_SQL.GetLoginUserInfo, matchAccount[0].Id).ToOne <AdminUser>(); return(CoffeeMapper <AdminUser, Account_ShowDTO> .AutoMap(loginUser, (tOut, tIn) => { tOut.Name = tIn["NAME"].ToString(); tOut.Roles = tIn["ROLESNAME"].ToString(); })); } else if (matchAccount.Count <= 0) { throw new PushToUserException("the entered account or password is incorrect"); } else { throw new Exception($"Duplicate Account : [account='{account}', password='******']"); } } }
public void ChangePassword(string oldPassword, string newPassword, string repeatPassword, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <AdminUser> commonService = new CommonService <AdminUser>(dbContext); var item = commonService.WhereNoMarkDeleted().Where(t => t.Id == updater).Select().ToOne(); if (null == item) { throw new PushToUserException("Current account item is not exist"); } if (newPassword != repeatPassword) { throw new PushToUserException("兩次輸入的密碼不一致"); } if (newPassword.Length < 6) { throw new PushToUserException("密碼最少6位"); } if (item.PasswordHash != oldPassword) { throw new PushToUserException("Old Password is not right"); } var updateItem = item; updateItem.PasswordHash = newPassword; updateItem.Updater = updater; dbContext.Update(updateItem); } }
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 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 IEnumerable <Role_ShowDTO> SearchItemsPaged(int?pageNum = null, int?pageSize = null, string name = null) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { string searchSql = RoleService_SQL.SearchAllRoleInfo; //查询条件 if (!string.IsNullOrEmpty(name)) { searchSql += " and A.NAME = {0}"; } var query = dbContext.Queryable(searchSql, name); //分页 if (pageNum.HasValue && pageSize.HasValue) { query = query.Paging(pageNum.Value, pageSize.Value); } var items = query.ToList <Role>(); return(null == items ? new List <Role_ShowDTO>() : items.Select(d => CoffeeMapper <Role, Role_ShowDTO> .AutoMap(d, (tout, tin) => { tout.HasApiPermissionIds = tin["HAS_API_PERMIDS"].ToString().Split(',').Where(s => !string.IsNullOrEmpty(s)).ToArray(); tout.HasMenuIds = tin["HAS_MENUIDS"].ToString().Split(',').Where(s => !string.IsNullOrEmpty(s)).ToArray(); }))); } }
public IEnumerable <Permission_ShowDTO> SearchItemsPaged(int?pageNum = null, int?pageSize = null, string apiType = null, string nameKey = null) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(dbContext); var search = commonService.WhereNoMarkDeleted().Where(p => p.PermissionType == 1); //查询条件 if (!string.IsNullOrEmpty(apiType)) { search = search.Where(p => p.ApiType.Equals(apiType)); } if (!string.IsNullOrEmpty(nameKey)) { search = search.Where(p => p.Name.Contains(nameKey)); } //分页 if (pageNum.HasValue && pageSize.HasValue) { search.OrderBy(t => t.SortNumber).Paging(pageNum.Value, pageSize.Value); } var items = search.Select().ToList(); return(null == items ? new List <Permission_ShowDTO>() : items.Select(d => CoffeeMapper <Permission, Permission_ShowDTO> .AutoMap(d)).ToList()); } }
public IEnumerable <Dictionary_ShowDTO> SearchItemsPaged(int?pageNum = null, int?pageSize = null, string type = null) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Dictionary> commonService = new CommonService <Dictionary>(dbContext); var search = commonService.WhereNoMarkDeleted(); //查询条件 if (!string.IsNullOrEmpty(type)) { search = search.Where(d => d.Type.Equals(type)); } //分页 if (pageNum.HasValue && pageSize.HasValue) { search.OrderBy(t => t.SortNumber).Paging(pageNum.Value, pageSize.Value); } var items = search.Select().ToList(); return(null == items ? new List <Dictionary_ShowDTO>() : items.Select(d => CoffeeMapper <Dictionary, Dictionary_ShowDTO> .AutoMap(d)).ToList()); } }
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 bool JudgeIfAccountHasPerms(string accountId, params string[] apiUrls) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { bool judgeRes = false; foreach (string apiUrl in apiUrls) { var judgeData = dbContext.Queryable(AccountService_SQL.JudgeIfAccountHasApiPerm, Utils.UrlToHump(apiUrl.Trim('/')), accountId).ToData(); if (null == judgeData) { judgeRes = false; break; } else if (1 == Convert.ToInt32(judgeData)) { judgeRes = true; } else { judgeRes = false; break; } } return(judgeRes); } }
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 IEnumerable <Permission_ShowDTO> GetAccountHasApiPerms(string accountId) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { var items = dbContext.Queryable(PermissionService_SQL.SearchAccountHasApiPerms, accountId).ToList <Permission>(); return(null == items ? new List <Permission_ShowDTO>() : items.Select(d => CoffeeMapper <Permission, Permission_ShowDTO> .AutoMap(d))); } }
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 IEnumerable <Department_ShowDTO> GetAllItems() { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Department> commonService = new CommonService <Department>(dbContext); var items = commonService.GetAllNoMarkDeleted().OrderBy(t => t.SortNumber).ToList(); return(null == items ? new List <Department_ShowDTO>() : items.Select(d => CoffeeMapper <Department, Department_ShowDTO> .AutoMap(d))); } }
public IEnumerable <Menu_ShowDTO> GetAccountHasNavMenus(string accountId) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { var items = dbContext.Queryable(MenuService_SQL.SearchAccountHasNavMenus, accountId).ToList <Menu>(); return(null == items ? new List <Menu_ShowDTO>() : items.Select(d => CoffeeMapper <Menu, Menu_ShowDTO> .AutoMap(d, (tout, tin) => { tout.IsMenuItem = (2 == tin.Type); })).OrderBy(m => m.SortNumber).ToList()); } }
public IEnumerable <Menu_ShowDTO> GetAllItems() { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Menu> commonService = new CommonService <Menu>(dbContext); var items = commonService.GetAllNoMarkDeleted().OrderBy(t => t.SortNumber).ToList(); return(null == items ? new List <Menu_ShowDTO>() : items.Select(d => CoffeeMapper <Menu, Menu_ShowDTO> .AutoMap(d, (tout, tin) => { tout.IsMenuItem = (2 == tin.Type); }))); } }
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 void ChangeMessageStatus(int status, params string[] messageIds) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { string updateSql = MessageService_SQL.UpdateMessageStatus; List <object> _sqlParams = new List <object>(); _sqlParams.Add(status); string messageIdsJoin = messageIds.Length == 0 ? string.Empty : string.Join(",", messageIds); _sqlParams.Add(messageIdsJoin); dbContext.ExecuteSql(updateSql, _sqlParams.ToArray()); } }
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 string AddNewOne(Account_AddEditDTO addOne, string creater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <AdminUser> commonAdminUserService = new CommonService <AdminUser>(dbContext); CommonService <AdminUserInfo> commonAdminUserInfoService = new CommonService <AdminUserInfo>(dbContext); bool hasExist = commonAdminUserService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Account.Equals(addOne.Account)).Any(); if (hasExist) { throw new PushToUserException($"A admin user item with the same account '{addOne.Account}' already exists"); } try { dbContext.DBTransaction.Begin(); AdminUser newAdminUserOne = CoffeeMapper <Account_AddEditDTO, AdminUser> .AutoMap(addOne, (_out, _in) => { _out.PasswordHash = "ensky123."; //系統默認密碼 _out.Id = Utils.GetGuidStr(); _out.Creater = creater; }); string accountId = commonAdminUserService.Insert(newAdminUserOne); AdminUserInfo newAdminUserInfoOne = CoffeeMapper <Account_AddEditDTO, AdminUserInfo> .AutoMap(addOne, (_out, _in) => { _out.Id = Utils.GetGuidStr(); _out.Creater = creater; _out.AdminUserId = accountId; }); commonAdminUserInfoService.Insert(newAdminUserInfoOne); dbContext.DBTransaction.Commit(); return(accountId); } 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 string AddNewOne(Department_AddEditDTO addOne, string creater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Department> commonService = new CommonService <Department>(dbContext); bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(addOne.Name)).Any(); if (hasExist) { throw new PushToUserException($"A Department item with the same name '{addOne.Name}' already exists"); } Department newOne = CoffeeMapper <Department_AddEditDTO, Department> .AutoMap(addOne, (_out, _in) => { _out.Id = Utils.GetGuidStr(); _out.Creater = creater; }); return(commonService.Insert(newOne)); } }
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; } } }
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 string AddNewOne(Permission_AddEditDTO addOne, string creater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(dbContext); bool hasExist = commonService.WhereNoMarkDeleted().Where(p => 0 == p.DelFlag && p.ApiUrl.Equals(addOne.ApiUrl)).Any(); if (hasExist) { throw new PushToUserException($"A api permission item with the same api url '{addOne.ApiUrl}' already exists"); } Permission newOne = CoffeeMapper <Permission_AddEditDTO, Permission> .AutoMap(addOne, (_out, _in) => { _out.Id = Utils.GetGuidStr(); _out.Creater = creater; _out.PermissionType = 1; }); return(commonService.Insert(newOne)); } }
public IEnumerable <Account_ShowDTO> SearchItemsPaged(int?pageNum = null, int?pageSize = null, string name = null, string account = null) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { string searchSql = AccountService_SQL.SearchAllAccountInfo; List <object> _sqlParams = new List <object>(); //查询条件 if (!string.IsNullOrEmpty(name)) { searchSql += $" and B.NAME = {{{_sqlParams.Count}}}"; _sqlParams.Add(name); } if (!string.IsNullOrEmpty(account)) { searchSql += $" and A.ACCOUNT = {{{_sqlParams.Count}}}"; _sqlParams.Add(account); } var query = dbContext.Queryable(searchSql, _sqlParams.ToArray()); //分页 if (pageNum.HasValue && pageSize.HasValue) { query = query.Paging(pageNum.Value, pageSize.Value); } var items = query.ToList <AdminUser>(); return(null == items ? new List <Account_ShowDTO>() : items.Select(d => CoffeeMapper <AdminUser, Account_ShowDTO> .AutoMap(d, (tout, tin) => { tout.Name = tin["NAME"].ToString(); tout.HasRoleIds = tin["HASROLEIDS"].ToString().Split(',').Where(s => !string.IsNullOrEmpty(s)).ToArray(); tout.Roles = tin["ROLESNAME"].ToString(); }))); } }
public string AddNewOne(Menu_AddEditDTO addOne, string creater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Menu> commonService = new CommonService <Menu>(dbContext); bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(addOne.Name)).Any(); if (hasExist) { throw new PushToUserException($"A menu item with the same name '{addOne.Name}' already exists"); } if (!string.IsNullOrEmpty(addOne.PagePath)) { hasExist = commonService.WhereNoMarkDeleted().Where(d => d.PagePath.Equals(addOne.PagePath)).Any(); if (hasExist) { throw new PushToUserException($"A menu item with the same page path '{addOne.PagePath}' already exists"); } } try { dbContext.DBTransaction.Begin(); Menu newOne = CoffeeMapper <Menu_AddEditDTO, Menu> .AutoMap(addOne, (_out, _in) => { _out.Id = Utils.GetGuidStr(); _out.Creater = creater; }); string newMenuId = commonService.Insert(newOne); //菜单项添加对应的权限项记录 if (2 == addOne.Type) { Permission menuPerm = new Permission { Id = Utils.GetGuidStr(), Name = $"menu-({addOne.Name})", PermissionType = 2, MenuId = newMenuId, DelFlag = 0, Creater = creater }; dbContext.Add(menuPerm); } dbContext.DBTransaction.Commit(); return(newMenuId); } catch (Exception ex) { dbContext.DBTransaction.Rollback(); throw ex; } } }
public CommonService(MiniSenDbContext ctx) { this.ctx = ctx; }
public IEnumerable <Message_ShowDTO> SearchItemsPaged(int?pageNum = null, int?pageSize = null, int?type = null, int?status = null, string receiver = null, int?theTermDays = null) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Message> commonService = new CommonService <Message>(dbContext); var search = commonService.WhereNoMarkDeleted(); //查询条件 if (type.HasValue) { search = search.Where(d => d.Type == type.Value); } if (status.HasValue) { search = search.Where(d => d.Status == status.Value); } if (!string.IsNullOrEmpty(receiver)) { search = search.Where(d => d.Receiver == receiver); } if (theTermDays.HasValue) { DateTime theEarliestDateTime = DateTime.Now.AddDays(-theTermDays.Value); search = search.Where(d => d.CreateTime >= theEarliestDateTime); } //分页 if (pageNum.HasValue && pageSize.HasValue) { search.OrderBy(t => t.SortNumber).Paging(pageNum.Value, pageSize.Value); } var items = search.Select().ToList(); return(null == items ? new List <Message_ShowDTO>() : items.Select(d => CoffeeMapper <Message, Message_ShowDTO> .AutoMap(d, (tout, tin) => { switch (tin.Type) { case 1: tout.TypeText = "系統通知"; break; case 2: tout.TypeText = "個人消息"; break; default: tout.TypeText = "未知消息類型"; break; } switch (tin.Status) { case -1: tout.TypeText = "發送失敗"; break; case 0: tout.TypeText = "未發送"; break; case 1: tout.TypeText = "已發送"; break; case 2: tout.TypeText = "未閱讀"; break; case 3: tout.TypeText = "已閱讀"; break; default: tout.TypeText = "未知消息狀態"; break; } }))); } }