public async Task <IActionResult> AddExpense([FromBody] ExpenseRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _dataContext.Add(await _converterHelper.ToExpenseEntity(request)); await _dataContext.SaveChangesAsync(); TripEntity tripEntity = await _tripHelper.GetTripAsync(request.TripId); return(Ok(_converterHelper.ToTripResponse(tripEntity))); }
public async Task <ExpenseEntity> ToAddExpenseEntity(ExpenseViewModel model, string picturePath) { TripEntity tripEntity = await _tripHelper.GetTripAsync(model.TripId); return(new ExpenseEntity { Trip = tripEntity, User = tripEntity.User, ExpenseType = await _expenseHelper.GetExpenseTypeAsync(model.ExpenseId), Details = model.Details, Value = model.Value, Date = model.Date.ToUniversalTime(), PicturePath = picturePath, }); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } TripEntity tripEntity = await _tripHelper.GetTripAsync(id); if (tripEntity == null) { return(NotFound()); } TripViewModel tripViewModel = await _converterHelper.ToTripViewModel(tripEntity); return(View(tripViewModel)); }