public async Task <ActionResult> Post([FromBody] AccountWithPassword account)
        {
            try
            {
                var createdAccount = await Mediator.Send(new CreateAccountRequest(account));

                return(CreatedAtAction(nameof(Get), new { id = createdAccount.AccountId }, createdAccount));
            }
            catch (DuplicatedLoginDALException e)
            {
                _logger.LogError(e.Message, e);
                return(BadRequest(e.Message));
            }
            catch (DALException e)
            {
                _logger.LogError("Attempt to add account failed", e);
                return(BadRequest("Attempt to add account failed."));
            }
        }
Ejemplo n.º 2
0
        public void ModelAccountWithPasswordToEntityAccount()
        {
            var model = new AccountWithPassword()
            {
                AccountId            = 1,
                ProvinceId           = 2,
                Agreement            = true,
                Login                = "******",
                Password             = "******",
                PasswordConfirmation = "passwordConfirmation"
            };
            //
            var entity = _mapper.Map <Account>(model);

            //
            entity.AccountId.Should().Be(entity.AccountId);
            entity.ProvinceId.Should().Be(entity.ProvinceId);
            entity.Agreement.Should().Be(entity.Agreement);
            entity.Login.Should().Be(entity.Login);
        }
 public CreateAccountRequest(AccountWithPassword account)
 {
     Account = account ?? throw new ArgumentNullException(nameof(account));
 }