Beispiel #1
0
        public async Task NovaConta_UsuarioAindaNaoExiste_DeveCadastrarComSucesso()
        {
            var(AccountRepository, BusinessContext) = new Build().GetNewAccountRepository();

            var newAccount = new AccountModel("Assane", "Diop", GenderType.Male, "LUPIN", "*****@*****.**");

            await AccountRepository.AddAsync(newAccount);

            await BusinessContext.CommitTransactionAsync();

            int countActual = (await AccountRepository.GetAllAsync()).Count();

            Assert.Equal(SeedData.GetAccounts().Count() + 1, countActual);
        }
Beispiel #2
0
        public async Task <IActionResult> Create(Account myEntity)
        {
            var dd = new AccountDto();

            if (ModelState.IsValid)
            {
                await _repository.AddAsync(myEntity);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["WalletId"] = new SelectList(await _walletRepository.FindByClause(), "WalletId", "Code", myEntity.WalletId);

            return(View(myEntity));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //创建数据库上下文
            var context = new SampleDbContext(new MySqlDbContextOptions("Sample", "数据库连接字符串,请先创建表,sql文件在Sql目录"));

            //创建仓储
            var accountRepository = new AccountRepository(context);

            var account = new Account
            {
                UserName    = "******" + DateTime.Now.ToString("yyyyMMddHHmmss"),
                Email       = "test",
                Password    = "******",
                Phone       = "test",
                Creator     = Guid.NewGuid(),
                ClosedBy    = Guid.Empty,
                ClosedTime  = DateTime.Now,
                CreatedTime = DateTime.Now,
                LastLoginIP = "test"
            };

            //添加账户
            var r = accountRepository.AddAsync(account).Result;

            Console.WriteLine(account.Id);

            //查询
            var paging = new Paging();
            var list   = accountRepository.Query(paging).Result;

            foreach (var acc in list)
            {
                Console.WriteLine($"ID:{acc.Id},UserName:{acc.UserName}");
            }

            Console.WriteLine($"共查询到{paging.TotalCount}数据");

            //修改
            account          = accountRepository.GetAsync(account.Id).Result;
            account.UserName = "******";
            var c = accountRepository.UpdateAsync(account).Result;

            Console.WriteLine($"修改{account.Id}");

            //删除
            var d = accountRepository.RemoveAsync(account.Id).Result;

            Console.WriteLine($"删除{account.Id}");
        }
        public async Task Poprawne_dodanie_nowego_użytkownika_do_bazy_danych()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <DataBaseContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new DataBaseContext(options);

            Account            account           = new Account(Guid.NewGuid(), "test", "test", "*****@*****.**", "secret");
            IAccountRepository accountRepository = new AccountRepository(context);
            // Act
            await accountRepository.AddAsync(account);

            Account existAccount = await accountRepository.GetAsync(account.Id);

            // Assert
            Assert.Equal(account, existAccount);
        }
        public async Task <int> CreateAccountAsync(SignUpRequest request)
        {
            var account = _mapper.Map(request,
                                      new Account
            {
                EmailVerificationCode = CryptoHelper.GenerateToken(KeyLength.EmailVerificationCode),
                PasswordHash          = PasswordHelper.HashPassword(request.Password),
            });
            await _repository.AddAsync(account);

            await _emailService.SendMailAsync(request.Email,
                                              $"[Localizer] Hello {request.Name}, checkout email confirm code.",
                                              $@"""
Helle {request.Name}!

Welcome to localizer! Your verification code is '{account.EmailVerificationCode}'.
Please use it when you first login time.

Thank you.
From Localizer team.
""");

            return(account.Id);
        }