public async Task <IActionResult> Create(Goal goal) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _goalService.AddGoalAsync(goal); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Add([FromBody] GoalCreateRequestDTO model) { try { var goal = new GoalModel() { GoalName = model.GoalName, TotalAmount = model.Amount, Type = model.Type, UserID = model.UserId, CurrentAmount = model.CurAmount ?? 0, CompleteDate = model.CompleteDate ?? null, CurrencyID = 1 // TODO }; var id = await _goalService.AddGoalAsync(goal); return(Created("", id)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }