Пример #1
0
        public async Task <long> AddAsync(long id, string typeName, string mobile, string code, string password, string tradePassword)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                string adderMobile = (await dbc.GetAll <PlatformUserEntity>().SingleOrDefaultAsync(p => p.Id == id)).Mobile;
                var    type        = await dbc.GetAll <PlatformUserTypeEntity>().SingleOrDefaultAsync(p => p.Name == typeName);

                if (type == null)
                {
                    return(-1);
                }
                PlatformUserEntity user = new PlatformUserEntity();
                if (typeName == "平台")
                {
                    user.PlatformUserTypeId = type.Id;
                    user.AdderMobile        = adderMobile;
                    user.Mobile             = mobile;
                    user.Code          = code;
                    user.Password      = password;
                    user.TradePassword = tradePassword;
                }
                else if (typeName == "商家")
                {
                    user.PlatformUserTypeId = type.Id;
                    user.AdderMobile        = adderMobile;
                    user.Mobile             = mobile;
                    user.Code          = code;
                    user.Salt          = CommonHelper.GetCaptcha(4);
                    user.Password      = CommonHelper.GetMD5(password + user.Salt);
                    user.TradePassword = CommonHelper.GetMD5(tradePassword + user.Salt);
                }
                else
                {
                    user.PlatformUserTypeId = type.Id;
                    user.AdderMobile        = adderMobile;
                    user.Mobile             = mobile;
                    user.Code          = code;
                    user.Salt          = CommonHelper.GetCaptcha(4);
                    user.Password      = password;
                    user.TradePassword = CommonHelper.GetMD5(tradePassword + user.Salt);
                }
                dbc.PlatformUsers.Add(user);
                await dbc.SaveChangesAsync();

                return(user.Id);
            }
        }
Пример #2
0
        public PlatformUserDTO ToDTO(PlatformUserEntity entity)
        {
            PlatformUserDTO dto = new PlatformUserDTO();

            dto.Code                 = entity.Code;
            dto.CreateTime           = entity.CreateTime;
            dto.Description          = entity.Description;
            dto.ErrorCount           = entity.ErrorCount;
            dto.ErrorTime            = entity.ErrorTime;
            dto.GivingIntegral       = entity.GivingIntegral;
            dto.Id                   = entity.Id;
            dto.IsEnabled            = entity.IsEnabled;
            dto.Mobile               = entity.Mobile;
            dto.PlatformIntegral     = entity.PlatformIntegral;
            dto.PlatformUserTypeId   = entity.PlatformUserTypeId;
            dto.PlatformUserTypeName = entity.PlatformUserType.Name;
            dto.UseIntegral          = entity.UseIntegral;
            dto.AdderMobile          = entity.AdderMobile;
            return(dto);
        }
Пример #3
0
        public async Task <long> AddAsync(string adminMobile, string mobile, string description, string password)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                var user     = dbc.GetAll <AdminEntity>().SingleOrDefault(a => a.Mobile == mobile);
                var p_user_m = dbc.GetAll <PlatformUserEntity>().SingleOrDefault(p => p.Mobile == mobile);
                var p_user_c = dbc.GetAll <PlatformUserEntity>().SingleOrDefault(p => p.Mobile == mobile);
                if (user != null)
                {
                    return(-2);
                }
                if (p_user_m != null)
                {
                    return(-3);
                }
                if (p_user_c != null)
                {
                    return(-4);
                }
                long type = dbc.GetAll <PlatformUserTypeEntity>().SingleOrDefault(p => p.Name == "平台").Id;
                PlatformUserEntity u_entity = new PlatformUserEntity();
                u_entity.Code               = mobile;
                u_entity.Mobile             = mobile;
                u_entity.AdderMobile        = adminMobile;
                u_entity.Salt               = CommonHelper.GetCaptcha(6);
                u_entity.Password           = CommonHelper.GetMD5(password);
                u_entity.TradePassword      = CommonHelper.GetMD5(password);
                u_entity.PlatformUserTypeId = type;
                dbc.PlatformUsers.Add(u_entity);

                AdminEntity entity = new AdminEntity();
                entity.Mobile      = mobile;
                entity.Description = description;
                entity.Salt        = CommonHelper.GetCaptcha(4);
                entity.Password    = CommonHelper.GetMD5(password + entity.Salt);
                dbc.Admins.Add(entity);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }