public void AMappedDTOKeepsTheSameGuid() { AccountForCreationDTO dto = new AccountForCreationDTO(); Account account = MapperHelper.GetMapped <Account>(dto); Assert.AreEqual(dto.Id, account.Id); }
public async Task <IActionResult> CreateAccount([FromBody] AccountForCreationDTO account) { var accountEntity = _mapper.Map <Account>(account); _repository.Account.CreateAccount(accountEntity); await _repository.SaveAsync(); var accountToReturn = _mapper.Map <AccountDTO>(accountEntity); return(CreatedAtRoute("AccountById", new { accountId = accountToReturn.AccountId }, accountToReturn)); }
public IActionResult CreateAccount(AccountForCreationDTO dto) { if (dto == null) { Ctrl.Logger.LogError("Owner object sent from client is null."); return(Ctrl.BadRequest("Owner object is null")); } if (!Ctrl.ModelState.IsValid) { Ctrl.Logger.LogError("Invalid owner object sent from client."); return(Ctrl.BadRequest("Invalid model object")); } var credential = Ctrl.Repository.Account.GetAccountCredential(dto.Id); if (credential != null) { string mailAddress = dto.Credential.MailAddress; string message = $"An account with the email {mailAddress} is already registered "; throw new RepositoryException(Ctrl.Conflict(message)); } dto.Credential.RegistrationDate = DateTime.Now; var accountEntity = Ctrl.Mapper.Map <Account>(dto); accountEntity.Credential.AccountId = accountEntity.Id; Ctrl.Repository.Account.CreateAccount(accountEntity); Ctrl.Repository.Save(); var createdAccount = Ctrl.Mapper.Map <AccountDTO>(accountEntity); return(Ctrl.CreatedAtRoute("GetAccountById", new { id = createdAccount.Id }, createdAccount)); }
public IActionResult CreateAccount([FromBody] AccountForCreationDTO account) { return(HandleOnDTO(account, AccountLgc.CreateAccount)); }