public async Task <CreateAdminOutput> CreateAdmin(CreateAdminInput dto)
        {
            var output = new CreateAdminOutput {
                Result = dto.Result
            };

            if (await this.AccountRpository.ExistedAsync(dto.Model.UserName))
            {
                output.Result.ResultCode = (int)AccountResultCode.UserNameExisted;
                output.Result.Message    = "该用户名存在";
                return(output);
            }
            var account = new TAccount
            {
                Name     = dto.Model.UserName,
                Password = dto.Model.Password,
                Type     = dto.Model.AccountType,
                Emai     = dto.Model.Email,
            };

            account.SetCreator(1);
            account.SetUpdater(1);
            await this.AccountRpository.AddAsync(account);

            var amax = await this.AdminRpository.GetMaxJobNumber();

            var cmax = await this.CustomerRpository.GetMaxJobNumber();

            var admin = new TAdmin
            {
                AccountId = account.Id,
                JobNumber = JobNumberUtils.GetJobNumber(amax, cmax),
            };

            admin.SetCreator(1);
            admin.SetUpdater(1);
            await this.AdminRpository.AddAsync(admin);

            if (!await this.SaveChangesAsync())
            {
                output.Result.Message = "数据保存失败";
                return(output);
            }
            output.Result.ResultCode = (int)ResultCode.Successful;
            return(output);
        }
Exemple #2
0
        public async Task <ResponseModel> AddAdminAccount(AddAdminDto dto)
        {
            if (await this.DbContext.TAccount.FindAsync(new { Name = dto.Model.UserName }) != null)
            {
                dto.Result.ResultCode = (int)AccountResultCode.UserNameExisted;
                dto.Result.Message    = "该用户名存在";
                return(dto.Result);
            }

            //插入TAccount
            var account = new TAccount
            {
                Name     = dto.Model.UserName,
                Password = dto.Model.Password,
                Type     = dto.Model.AccountType,
                Emai     = dto.Model.Email,
            };

            account.SetCreator(1);
            account.SetUpdater(1);
            await this.DbContext.AddOneAsync(account);

            var amax = await this.GetAdminMaxJobNumber();

            var cmax = await this.GetCustomerMaxJobNumber();

            //插入TAdmin
            var admin = new TAdmin
            {
                AccountId = account.Id,
                JobNumber = JobNumberUtils.GetJobNumber(amax, cmax),
            };

            admin.SetCreator(1);
            admin.SetUpdater(1);
            await this.DbContext.AddOneAsync(admin);

            if (await this.DbContext.SaveChangesAsync() <= 0)
            {
                dto.Result.Message = "数据保存失败";
                return(dto.Result);
            }
            dto.Result.ResultCode = (int)ResultCode.Successful;
            return(dto.Result);
        }