public IActionResult CreateOwner([FromBody] OwnerCreateDto owner) { try { if (owner == null) { _logger.LogError("Owner object sent from client is null."); return(BadRequest("Owner object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid owner object sent from client."); return(BadRequest("Invalid model object")); } var ownerEntity = _mapper.Map <Owner>(owner); _repository.Owner.CreateOwner(ownerEntity); _repository.Commit(); var createdOwner = _mapper.Map <OwnerViewModel>(ownerEntity); // CreatedAtRoute return 201 for creation so we can see this is a create operation. return(CreatedAtRoute("OwnerById", new { id = createdOwner.Id }, createdOwner)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreateOwner action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
// GET: Authenticate/Create public async Task <ActionResult> Create([FromBody] User user) { await _repository.User.CreateBasicUser(user); _repository.Commit(); return(Ok(user)); }
public IActionResult CreateAccount([FromBody] AccountCreateDto accountCreateDto) { try { if (accountCreateDto == null) { return(BadRequest("Account is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid account")); } var account = _mapper.Map <Account>(accountCreateDto); _repository.Account.CreateAccount(account); _repository.Commit(); var accountViewModel = _mapper.Map <AccountViewModel>(account); return(CreatedAtRoute("GetAccount", new { id = account.Id }, accountViewModel)); } catch (Exception) { return(StatusCode(500, "Internal Server Error")); } }
public void SaveToken(User user, Guid applicationId) { var appId = _repository.Application.GetWhere(x => x.Id == applicationId); if (appId == null) { throw new Exception("Application not found"); } _repository.Token.Create(new Token() { Content = user.Token, IssueDate = DateTime.Now, IssuedBy = _tokenConfig.Issuer, Application_Id = applicationId, User_Id = user.Id }); _repository.Commit(); }