public async Task <long> AddNew(string userName, string phoneNum, string password) { User user = new User() { UserName = userName, PhoneNum = phoneNum }; string salt = CommonHelper.CreateVerifyCode(5); user.PasswordSalt = salt; var passwordHash = CommonHelper.CalcMD5(password + salt); user.PasswordHash = passwordHash; using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); bool exists = await commonService.GetAll().AnyAsync(u => u.PhoneNum == phoneNum); bool exists2 = await commonService.GetAll().AnyAsync(u => u.UserName == userName); if (exists) { throw new ArgumentException("手机号" + phoneNum + "已经存在"); } if (exists2) { throw new ArgumentException("用户名" + userName + "已经存在"); } db.User.Add(user); await db.SaveChangesAsync(); return(user.Id); } }
public async Task <long> AddNew(string weixinName, string appid, string token, string encodingAESKey, string appsecret, string defaultResponse) { using (var db = new WeixinDbContext()) { CommonService <BaseConfig> service = new CommonService <BaseConfig>(db); var exists = await service.GetAll().AnyAsync(a => a.Appid == appid); if (exists) { throw new ArgumentException("该公众号appid已经存在"); } var config = new BaseConfig() { WeixinName = weixinName, Appid = appid, Token = token, EncodingAESKey = encodingAESKey, Appsecret = appsecret, DefaultResponse = defaultResponse }; db.BaseConfig.Add(config); await db.SaveChangesAsync(); return(config.Id); } }
public async Task <BaseConfigDTO[]> GetAll() { using (var db = new WeixinDbContext()) { CommonService <BaseConfig> commonService = new CommonService <BaseConfig>(db); return((await commonService.GetAll().AsNoTracking().ToListAsync()).Select(a => ToDTO(a)).ToArray()); } }
public async Task <HandlerConfigDTO[]> GetAll() { using (var db = new WeixinDbContext()) { var service = new CommonService <HandlerConfig>(db); return((await service.GetAll().AsNoTracking().ToListAsync()).Select(h => ToDTO(h)).ToArray()); } }
public async Task <BaseConfigDTO> GetByAppid(string appid) { using (var db = new WeixinDbContext()) { var entity = await db.BaseConfig.SingleOrDefaultAsync(b => b.Appid == appid); return(ToDTO(entity)); } }
public async Task <UserDTO> GetByPhoneNum(string phoneNum) { using (var db = new WeixinDbContext()) { var user = await db.User.SingleOrDefaultAsync(u => u.PhoneNum == phoneNum); return(ToDTO(user)); } }
public async Task <UserDTO> GetById(long userId) { using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); var user = await commonService.GetById(userId); return(ToDTO(user)); } }
public async Task <UserDTO[]> GetAll() { using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); var all = await commonService.GetAll().ToListAsync(); return((all.Select(u => ToDTO(u))).ToArray()); } }
public async Task <BaseConfigDTO> GetById(long id) { using (var db = new WeixinDbContext()) { CommonService <BaseConfig> service = new CommonService <BaseConfig>(db); var entity = await service.GetById(id); return(ToDTO(entity)); } }
//该公众号的所有父菜单配置 public async Task <ParentMenuConfigDTO[]> GetAll(int weixinId) { using (var db = new WeixinDbContext()) { CommonService <ParentMenuConfig> commonService = new CommonService <ParentMenuConfig>(db); var list = await commonService.GetAll().Where(p => p.WeixinID == weixinId).ToListAsync(); return(list.Select(p => ToDTO(p)).ToArray()); } }
public async Task <PermissionDTO[]> GetAll() { using (var db = new WeixinDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(db); var perms = await commonService.GetAll().ToListAsync(); return(perms.Select(p => ToDTO(p)).ToArray()); } }
public async Task <PermissionDTO> GetById(long id) { using (var db = new WeixinDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(db); var perm = await commonService.GetById(id); return(perm == null ? null : ToDTO(perm)); } }
public async Task <RoleDTO[]> GetByName(string roleName) { using (var db = new WeixinDbContext()) { CommonService <Role> commonService = new CommonService <Role>(db); var roles = commonService.GetAll().Where(r => r.RoleName.Contains(roleName)); var list = await roles.ToListAsync(); return(list.Select(r => ToDTO(r)).ToArray()); } }
public async Task <SubMenuConfigDTO[]> GetAll(long parentMenuID) { using (var db = new WeixinDbContext()) { CommonService <SubMenuConfig> commonService = new CommonService <SubMenuConfig>(db); var list = await commonService.GetAll().Include(s => s.ParentMenuConfig) .Where(s => s.ParentMenuID == parentMenuID).ToListAsync(); return(list.Select(s => ToDTO(s)).ToArray()); } }
public async Task <BaseConfigDTO[]> GetByName(string weixinName) { using (var db = new WeixinDbContext()) { CommonService <BaseConfig> service = new CommonService <BaseConfig>(db); var entity = service.GetAll().Where(b => b.WeixinName.Contains(weixinName)); var list = await entity.ToListAsync(); return(list.Select(b => ToDTO(b)).ToArray()); } }
public async Task <PermissionDTO[]> GetByName(string permissionName) { using (var db = new WeixinDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(db); var perms = commonService.GetAll().Where(r => r.PermissionName.Contains(permissionName)); var list = await perms.ToListAsync(); return(list.Select(p => ToDTO(p)).ToArray()); } }
public async Task <PermissionDTO[]> GetByRoleId(long roleId) { using (var db = new WeixinDbContext()) { CommonService <Role> commonService = new CommonService <Role>(db); var role = await commonService.GetById(roleId); if (role == null) { throw new ArgumentException("角色不存在"); } return(role.Permissions.ToList().Select(p => ToDTO(p)).ToArray()); } }
public async Task <long> AddNew(string roleName) { using (var db = new WeixinDbContext()) { var role = new Role() { RoleName = roleName }; db.Role.Add(role); await db.SaveChangesAsync(); return(role.Id); } }
public async Task <RoleDTO[]> GetByUserId(long userId) { using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); var user = await commonService.GetById(userId); if (user == null) { throw new ArgumentException("用户未找到"); } return(user.Roles.ToList().Select(r => ToDTO(r)).ToArray()); } }
public async Task <RoleDTO> GetById(long roleId) { using (var db = new WeixinDbContext()) { CommonService <Role> commonService = new CommonService <Role>(db); var role = await commonService.GetById(roleId); if (role == null) { throw new ArgumentException("角色未找到"); } return(ToDTO(role)); } }
public async Task Edit(long roleId, string roleName) { using (var db = new WeixinDbContext()) { CommonService <Role> commonService = new CommonService <Role>(db); var role = await commonService.GetById(roleId); if (role == null) { throw new ArgumentException("该角色不存在!"); } role.RoleName = roleName; await db.SaveChangesAsync(); } }
public async Task Delete(long roleId) { using (var db = new WeixinDbContext()) { CommonService <Role> commonService = new CommonService <Role>(db); var role = await commonService.GetById(roleId); if (role == null) { throw new ArgumentException("该角色不存在!"); } db.Role.Remove(role); await db.SaveChangesAsync(); } }
public async Task Delete(long id) { using (var db = new WeixinDbContext()) { CommonService <HandlerConfig> service = new CommonService <HandlerConfig>(db); var handleConfig = await service.GetById(id); if (handleConfig == null) { throw new ArgumentException("该公众号不存在"); } db.HandlerConfig.Remove(handleConfig); await db.SaveChangesAsync(); } }
public async Task Delete(long id) { using (var db = new WeixinDbContext()) { CommonService <SubMenuConfig> commonService = new CommonService <SubMenuConfig>(db); var entity = await commonService.GetById(id); if (entity == null) { throw new ArgumentException("未找到菜单配置"); } db.SubMenuConfig.Remove(entity); await db.SaveChangesAsync(); } }
public async Task Delete(long userId) { using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); var user = await commonService.GetById(userId); if (user == null) { throw new ArgumentException("用户不存在!"); } db.User.Remove(user); await db.SaveChangesAsync(); } }
public async Task Delete(long id) { using (var db = new WeixinDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(db); var entity = await commonService.GetById(id); if (entity == null) { throw new ArgumentException("该权限项不存在"); } db.Permission.Remove(entity); await db.SaveChangesAsync(); } }
public async Task Delete(long id) { using (var db = new WeixinDbContext()) { var commonService = new CommonService <BaseConfig>(db); var config = await commonService.GetById(id); if (config == null) { throw new ArgumentNullException(); } db.BaseConfig.Remove(config); await db.SaveChangesAsync(); } }
public async Task <bool> CheckLogin(string userName, string password) { using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); var user = await commonService.GetAll().SingleOrDefaultAsync(u => u.UserName == userName); if (user == null) { return(false); } string dbPasswordHash = user.PasswordHash; //取出数据库中的密码hash string inputPasswordHash = CommonHelper.CalcMD5(user.PasswordSalt + password); //根据输入的密码计算出hash return(dbPasswordHash == inputPasswordHash); } }
public async Task Edit(long id, string permissionName, string description) { using (var db = new WeixinDbContext()) { CommonService <Permission> commonService = new CommonService <Permission>(db); var entity = await commonService.GetById(id); if (entity == null) { throw new ArgumentException("该权限项不存在"); } entity.Description = description; entity.PermissionName = permissionName; await db.SaveChangesAsync(); } }
public async Task Edit(long userId, string phoneNum, string password) { using (var db = new WeixinDbContext()) { CommonService <User> commonService = new CommonService <User>(db); var user = await commonService.GetById(userId); if (user == null) { throw new ArgumentException("该用户不存在!"); } user.PhoneNum = phoneNum; user.PasswordHash = CommonHelper.CalcMD5(user.PasswordSalt + password); await db.SaveChangesAsync(); } }