private Account _mapAccountToEntity(AccountForEditingDto account) { var newAccount = new Account() { Id = 0, Name = account.Name, Description = account.Description }; return(newAccount); }
public async Task <Uri> CreateAccountAsync(AccountForEditingDto account) { string reqUrl = baseUrl; //var request = new HttpRequestMessage(HttpMethod.Post, reqUrl); //request.Headers.Add("ContentType", "application/json"); var client = _clientFactory.CreateClient(); HttpResponseMessage response = await client.PostAsJsonAsync(reqUrl, account); response.EnsureSuccessStatusCode(); // return URI of the created resource. return(response.Headers.Location); }
public async Task <ActionResult> Create(AccountForEditingDto account) { if (ModelState.IsValid) { // Send til service Uri uri = await _svc.CreateAccountAsync(account); var parts = uri.AbsolutePath.ToString().Split('/'); var idFromUri = parts.Last(); return(RedirectToAction("Details", new { id = idFromUri })); } else { return(View(account)); } }
public IActionResult CreateAccount( [FromBody] AccountForEditingDto account) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var finalAccount = _mapAccountToEntity(account); _accountRepo.CreateAccount(finalAccount); if (!_accountRepo.Save()) { return(StatusCode(500, "A problem occured handling your request")); } // Todo finalAccount.id = 0 her... return(CreatedAtRoute("GetAccount", new { id = finalAccount.Id }, finalAccount)); ////ToDo Change //var maxId = AccountsDataStore.Current.Accounts.Max(a => a.Id); //var finishedAccount = new AccountDto() //{ // Id = ++maxId, // Name = account.Name, // Description = account.Description //}; //AccountsDataStore.Current.Accounts.Add(finishedAccount); }