Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public async Task Delete(long id)
        {
            var data = await GetById(id);

            data.IsDeleted = true;
            await db.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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();
            }
        }
Ejemplo n.º 6
0
        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();
            }
        }
Ejemplo n.º 7
0
        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();
            }
        }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        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();
            }
        }
Ejemplo n.º 10
0
        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();
            }
        }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 12
0
        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();
            }
        }
Ejemplo n.º 13
0
        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();
            }
        }
        public async Task <long> AddNew(string menuName, int menuOrder, int weixinId)
        {
            using (var db = new WeixinDbContext())
            {
                var entity = new ParentMenuConfig()
                {
                    MenuName  = menuName,
                    MenuOrder = menuOrder,
                    WeixinID  = weixinId
                };
                db.ParentMenuConfig.Add(entity);
                await db.SaveChangesAsync();

                return(entity.Id);
            }
        }
Ejemplo n.º 15
0
        public async Task Edit(long id, string appId, string className, string handlerName)
        {
            using (var db = new WeixinDbContext())
            {
                CommonService <HandlerConfig> service = new CommonService <HandlerConfig>(db);
                var handleConfig = await service.GetById(id);

                if (handleConfig == null)
                {
                    throw new ArgumentException("该公众号不存在");
                }
                handleConfig.AppId       = appId;
                handleConfig.ClassName   = className;
                handleConfig.HandlerName = handlerName;
                await db.SaveChangesAsync();
            }
        }
        public async Task Edit(long id, string menuName, int menuOrder, int weixinId)
        {
            using (var db = new WeixinDbContext())
            {
                CommonService <ParentMenuConfig> commonService = new CommonService <ParentMenuConfig>(db);
                var entity = await commonService.GetById(id);

                if (entity == null)
                {
                    throw new ArgumentException("未找到该菜单配置");
                }
                entity.MenuName  = menuName;
                entity.MenuOrder = menuOrder;
                entity.WeixinID  = weixinId;
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 17
0
        public async Task Edit(long id, string weixinName, string token, string encodingAESKey, string appsecret,
                               string defaultResponse)
        {
            using (var db = new WeixinDbContext())
            {
                var commonService = new CommonService <BaseConfig>(db);
                var config        = await commonService.GetById(id);

                if (config == null)
                {
                    throw new ArgumentNullException("公众号不存在");
                }
                config.WeixinName      = weixinName;
                config.Token           = token;
                config.EncodingAESKey  = encodingAESKey;
                config.Appsecret       = appsecret;
                config.DefaultResponse = defaultResponse;
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 18
0
        public async Task Edit(long id, string type, string menuName, string keyUrlMediaId, long parentMenuID,
                               int menuOrder)
        {
            using (var db = new WeixinDbContext())
            {
                CommonService <SubMenuConfig> commonService = new CommonService <SubMenuConfig>(db);
                var entity = await commonService.GetById(id);

                if (entity == null)
                {
                    throw new ArgumentException("未找到菜单配置");
                }
                entity.Type          = type;
                entity.MenuName      = menuName;
                entity.KeyUrlMediaId = keyUrlMediaId;
                entity.ParentMenuID  = parentMenuID;
                entity.MenuOrder     = menuOrder;
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 19
0
        public async Task <long> AddNew(string type, string menuName, string keyUrlMediaId, long parentMenuID,
                                        int menuOrder)
        {
            var entity = new SubMenuConfig()
            {
                Type          = type,
                MenuName      = menuName,
                KeyUrlMediaId = keyUrlMediaId,
                ParentMenuID  = parentMenuID,
                MenuOrder     = menuOrder
            };

            using (var db = new WeixinDbContext())
            {
                db.SubMenuConfig.Add(entity);
                await db.SaveChangesAsync();

                return(entity.Id);
            }
        }
Ejemplo n.º 20
0
        public async Task AddPermissonIds(long roleId, long[] permissionIds)
        {
            using (var db = new WeixinDbContext())
            {
                CommonService <Role> roleCs = new CommonService <Role>(db);
                var role = await roleCs.GetById(roleId);

                if (role == null)
                {
                    throw new ArgumentException("该角色不存在");
                }
                CommonService <Permission> permissionCs = new CommonService <Permission>(db);
                var permissions = await permissionCs.GetAll().
                                  Where(p => permissionIds.Contains(p.Id)).ToArrayAsync();

                foreach (var item in permissions)
                {
                    role.Permissions.Add(item);
                }
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 21
0
        public async Task <long> AddNew(string permissionName, string description)
        {
            using (var db = new WeixinDbContext())
            {
                var entity = new Permission()
                {
                    PermissionName = permissionName,
                    Description    = description
                };
                CommonService <Permission> commonService = new CommonService <Permission>(db);
                var exists = await commonService.GetAll().AnyAsync(p => p.PermissionName == permissionName);

                if (exists)
                {
                    throw new ArgumentException("改权限项已经存在");
                }
                db.Permission.Add(entity);
                await db.SaveChangesAsync();

                return(entity.Id);
            }
        }
Ejemplo n.º 22
0
        public async Task AddRoleIds(long userId, long[] roleIds)
        {
            using (var db = new WeixinDbContext())
            {
                CommonService <User> userCs = new CommonService <User>(db);
                var user = await userCs.GetById(userId);

                if (user == null)
                {
                    throw new ArgumentException("用户不存在" + userId);
                }
                CommonService <Role> roleCs = new CommonService <Role>(db);

                //寻找数据库里的roleId和传入的roleId的交集
                var roles = roleCs.GetAll().Where(r => roleIds.Contains(r.Id)).ToArray();
                foreach (var role in roles)
                {
                    user.Roles.Add(role);
                }
                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 23
0
        public async Task <long> AddNew(string appId, string className, string handleName)
        {
            using (var db = new WeixinDbContext())
            {
                CommonService <HandlerConfig> service = new CommonService <HandlerConfig>(db);
                var handelConfig = new HandlerConfig()
                {
                    AppId       = appId,
                    ClassName   = className,
                    HandlerName = handleName
                };
                var exists = await service.GetAll().AnyAsync(s => s.AppId == appId);

                if (exists)
                {
                    throw new ArgumentException("该公众号appid已经存在");
                }
                db.HandlerConfig.Add(handelConfig);
                await db.SaveChangesAsync();

                return(handelConfig.Id);
            }
        }