public async Task<bool> CreateAccount(NewAccountViewModel model) { var username = HttpContext.Current.User.Identity.Name; User user = await _userManager.FindByNameAsync(username); Account account = new Account { UserId = user.Id, Household = user.Household, Name = model.Name }; // Id of newly inserted account is returned. bool result = await _accountData.InsertAccountAsync(account); return result; }
public async Task<IList<AccountDetailViewModel>> Create(NewAccountViewModel model) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); // HTTP STATUS CODE: 400 } bool result = await AccountManager.CreateAccount(model); if (!result) throw new HttpResponseException(HttpStatusCode.InternalServerError); IList<AccountDetailViewModel> accounts = await AccountManager.GetAccounts(); if (accounts == null) throw new HttpResponseException(HttpStatusCode.NotFound); return accounts; }