public async Task UpdateAsync( int id, string description, decimal amount, Category category, DateTime spentDate) { var expense = new UpdateExpenseBindingModel { Description = description, Amount = amount, Category = category, SpentDate = spentDate }; var expenseJson = new StringContent(JsonSerializer.Serialize(expense), Encoding.UTF8, "application/json"); await this.httpClient.PutAsync($"{URL_BASE}/{id}", expenseJson); }
public async Task <IActionResult> UpdateAsync(UpdateExpenseBindingModel bindingModel) { try { var userId = this.userResolverService.User.FindFirst(ClaimTypes.Name).Value; await this.expensesService.UpdateAsync( bindingModel.ExpenseId, bindingModel.Amount, bindingModel.Description, bindingModel.CategoryId, userId); return(this.NoContent()); } catch (Exception e) { return(this.BadRequest("Unable to update expense, please contact support")); } }
public async Task <IActionResult> PutExpense(int id, UpdateExpenseBindingModel model) { var expense = await this.expenseRepository.GetAsync(id); if (expense == null) { return(this.NotFound()); } expense.Amount = model.Amount; expense.Description = model.Description; expense.Category = model.Category; expense.SpentDate = model.SpentDate; if (!await this.expenseRepository.UpdateAsync(expense)) { if (!await this.expenseRepository.ExistsAsync(id)) { return(this.NotFound()); } } return(this.NoContent()); }