public IActionResult CreateAccount([FromBody] AccountForCreationDto account) { try { if (account == null) { _logger.LogError("Object sent from client is null."); return(BadRequest("Object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid object sent from client."); return(BadRequest("Invalid model object")); } var accountEntity = _mapper.Map <Account>(account); _repository.Account.CreateAccount(accountEntity); _repository.Save(); var createdAccount = _mapper.Map <AccountDto>(accountEntity); return(CreatedAtRoute("AccountById", new { id = createdAccount.Id }, createdAccount)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreateAccount action: {ex}"); return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> CreateAccount([FromBody] AccountForCreationDto account) { try { if (account == null) { _logger.LogInfo("Account object sent from client is null"); return(BadRequest("Account object is null")); } if (!ModelState.IsValid) { _logger.LogInfo("Invalid Account object sent from client."); return(BadRequest("Ivalid model object")); } var accountEntity = _mapper.Map <Account>(account); _repository.Account.Create(accountEntity); await _repository.SaveAsync(); var createdAccount = _mapper.Map <AccountDto>(accountEntity); return(CreatedAtRoute("AccountById", new { createdAccount.Id }, createdAccount)); } catch (Exception ex) { _logger.LogInfo($"Something went wrong inside CreateAccount action: {ex.Message}"); return(StatusCode(500, "Internal Server Error")); } }
public async Task <IActionResult> AddFirstAccount(int userId, AccountForCreationDto AccountForCreation) { var creator = await _userRepo.GetUser(userId); if (creator.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var Account = _mapper.Map <Account>(AccountForCreation); Account.User = creator; Account.Balance = 0; Account.Active = true; Account.IsBank = true; _repo.Add(Account); if (await _repo.SaveAll()) { var jobToReturn = _mapper.Map <AccountForReturnDto>(Account); return(CreatedAtRoute("GetAccount", new { Name = Account.Name, userId = userId }, jobToReturn)); } throw new Exception("Creation of Account failed on save"); }
public IActionResult CreateAccount([FromBody] AccountForCreationDto account) { try { if (account == null) { return(BadRequest("Account object is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } var accountEntity = _mapper.Map <Account>(account); _repository.Account.CreateAccount(accountEntity); _repository.Save(); var createdAccount = _mapper.Map <AccountDto>(accountEntity); return(CreatedAtRoute("GetAccountById", new { id = createdAccount.AccountId }, createdAccount)); } catch (Exception ex) { return(StatusCode(500, "Internal server error: " + ex.Message)); } }
public async Task <IActionResult> CreateAccount(int userId, int bankId, AccountForCreationDto accountForCreationDto) { var command = new CreateAccountCommand(accountForCreationDto); var result = await Mediator.Send(command); return(CreatedAtAction(nameof(GetAccountById), new { accountId = result.Id, bankId, userId }, result)); }
public JsonResult CreatePointOfInterest([FromBody] AccountForCreationDto account) { string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name; try { //Check value enter from the form if (account == null) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationAccount)); return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_ACCOUNT))); } if (!ModelState.IsValid) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound)); return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND))); } //Check email enter from the form exist in the database if (!_accountRepository.EmailExist(account.Email)) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailExist)); return(Json(MessageResult.GetMessage(MessageType.EMAIL_EXIST))); } //This is send email to vertified account SendGmail.SendVertified(account.Email); //Hash new password account.Password = PasswordUtil.CreateMD5(account.Password); //Map data enter from the form to account entity var finalAccount = Mapper.Map <PPT.Database.Entities.AccountEntity>(account); //This is query insert account _accountRepository.Register(finalAccount); if (!_accountRepository.Save()) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest)); return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST))); } Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.registerSuccess)); return(Json(MessageResult.GetMessage(MessageType.REGISTER_SUCCESS))); } catch (Exception ex) { Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message)); return(Json(MessageResult.ShowServerError(ex.Message))); } }
public ActionResult <AccountDto> CreateAccount(AccountForCreationDto account) { var accountEntity = _mapper.Map <Entities.Account>(account); _accountRepository.AddAccount(accountEntity); _accountRepository.Save(); var result = _mapper.Map <AccountDto>(accountEntity); return(CreatedAtRoute("GetAccount", new { account_id = result.Id }, new { status = "ok", result })); }
public async Task <ActionResult <AccountDto> > PostAccount([FromBody] AccountForCreationDto accountForCreationDto) { var userGuid = Guid.NewGuid(); var account = mapper.Map <Account>(accountForCreationDto); account.UserGuid = userGuid; await _context.Accounts.AddAsync(account); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAccount", new { userGuid = account.UserGuid, id = account.Id }, account)); }
public ActionResult CreateAccount([FromBody] AccountForCreationDto account) { var accountEntity = _mapper.Map <Account>(account); _easyKBTaskBoardRepository.AddAccount(accountEntity); _easyKBTaskBoardRepository.Save(); var accountToReturn = _mapper.Map <AccountDto>(accountEntity); return(CreatedAtRoute( "GetAccount", new { accountId = accountToReturn.Id }, accountToReturn)); }
private User AddBankAccount(User user) { AccountForCreationDto accountForCreation = new AccountForCreationDto { Name = "Bank", AccountType = "Asset" }; Account Bank = _mapper.Map <Account>(accountForCreation); Bank.IsBank = true; Bank.Active = true; user.Bank = Bank; return(user); }
public async Task <ActionResult <AccountDto> > CreateAccount(AccountForCreationDto createAccountDto) { // duplicate field validation var usernameExists = await UsernameExists(createAccountDto.Username); if (usernameExists) { return(Conflict("Username already exists")); } var emailExists = await EmailExists(createAccountDto.Email); if (emailExists) { return(Conflict("Email already exists")); } // since contact number is not required we should check if its null first if (createAccountDto.ContactNumber != null) { var contactExists = await ContactExists(createAccountDto.ContactNumber); if (contactExists) { return(Conflict("Contact Number already exists")); } } // map dto to entity var account = mapper.Map <Account> (createAccountDto); // add the registration date account.RegistrationDate = DateTime.Now; // save the account Accounts.Add(account); await context.SaveChangesAsync(); // return account dto at location var accountDto = mapper.Map <AccountDto> (account); return(CreatedAtAction(nameof(GetAccountById), new { id = accountDto.Id }, accountDto)); }
public IActionResult CreateAccount([FromBody] AccountForCreationDto account) { try { if (account == null) { _logger.LogError($"account object sent from client is null at: {DateTime.Now.ToString("dd/mm/YYYY HH:MM:SS")}"); return(BadRequest("account object is null")); } if (!ModelState.IsValid) { _logger.LogError($"account object sent from client is not invalid at: {DateTime.Now.ToString("dd/mm/YYYY HH:MM:SS")}"); return(BadRequest("account model is invalid")); } if (_repositoryWrapper.Owner.GetOwnerById(account.ownerid) == null) { _logger.LogError($"owner with id: {account.ownerid} has'nt been in db."); return(BadRequest($"owner with id: {account.ownerid} has'nt been in db.")); } var accountEntity = _mapper.Map <Account>(account); accountEntity.DateCreated = Convert.ToDateTime(DateTime.Now.ToString("yyyy-mm-dd")); _repositoryWrapper.Account.CreateAccount(accountEntity); _repositoryWrapper.Save(); var createdAccount = _mapper.Map <AccountDto>(accountEntity); return(CreatedAtRoute("accountById", new { Id = createdAccount.Id }, createdAccount)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreateOwner actio: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> CreateAccount(int userId, [FromBody] AccountForCreationDto accountForCreationDto) { var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (currentUserId != userId) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } accountForCreationDto.UserId = userId; if (await _repo.GetAccount(userId, accountForCreationDto.Accountname) != null) { return(BadRequest("Account already exists")); } var user = await _repo.GetUser(accountForCreationDto.UserId); // eens kijken of de mapper zo slim is dat ie de sender informatie ook invult in messageToReturn // zelfs bij de sender info die nu ietsanders heet. var account = _map.Map <Account>(accountForCreationDto); account.Balance = 0; _repo.Add(account); if (await _repo.SaveAll()) { var accountToReturn = _map.Map <AccountForDetailedDto>(account); return(CreatedAtRoute("GetAccount", new { id = account.Id }, accountToReturn)); } throw new Exception("Creating the account failed on save"); }
public IActionResult CreateAccount([FromBody] AccountForCreationDto account) { try { if (account == null) { _logger.LogError("Object compte envoyé au client est null."); return(BadRequest("Owner object is null")); } //*modelstate va verifier l état d un model specialement creer pour le CREATE, a savoir si il est valid et non null. //*il herite de la classe abstrait controllerBase if (!ModelState.IsValid) { _logger.LogError("Object compte envoyé au client n' est pas valide."); return(BadRequest("Invalid model object")); } //* si tt est ok : on map notre model dto avec le model generique OWNER var accEntity = _mapper.Map <Account>(account); //* on le fait passé en parametre via l interface irepositorywrapper ( qui est une couche generique ) //* qui elle va contenir une autre sous couche qui fait appel a la couche iownerRepository qui contien les methodes CRUD _repository.Account.CreateAccount(accEntity); //* on enregistre _repository.Save(); var createdAccount = _mapper.Map <AccountDto>(accEntity); return(CreatedAtRoute("AccountById", new { id = createdAccount.Id }, createdAccount)); } catch (Exception ex) { _logger.LogError($"une erreur c' est produite lors de la creation d' un compte action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public CreateAccountCommand(AccountForCreationDto accountForCreationDto) { AccountForCreationDto = accountForCreationDto; }