Esempio n. 1
0
        public async static Task <TAccount> Add()
        {
            var rpository = Game.Scene.GetComponent <AccountRpository>();
            var account   = new TAccount
            {
                FAccountName = "Sam" + new Random().Next(100000),
            };

            account.SetCreator("Admin");
            account.SetUpdater("Admin");
            await rpository.DBContext.InsertAsync(account);

            return(account);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async void TestInsertMany()
        {
            Game.Scene.AddComponent <MongoConfig>();
            var rpository = Game.Scene.GetComponent <AccountRpository>();

            List <TAccount> accounts = new List <TAccount>();

            for (var i = 0; i < 100; i++)
            {
                var account = new TAccount
                {
                    FAccountName = "SAM" + i,
                    FType        = AccountType.CustomerService,
                    FEmail       = "*****@*****.**",
                };
                account.SetCreator("TestInsertMany");
                accounts.Add(account);
            }
            rpository.DBContext.InsertMany(accounts);
        }