Esempio n. 1
0
        public async Task <IHttpActionResult> AddGoal([FromBody] GoalCreateRequestDTO model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest("You've sent an empty model"));
                }

                var goal = new Goal()
                {
                    GoalName     = model.GoalName,
                    Amount       = model.Amount,
                    Type         = model.Type,
                    UserId       = model.UserId,
                    IsActive     = true,
                    CurAmount    = model.CurAmount ?? 0,
                    CompleteDate = model.CompleteDate ?? null
                };

                _context.Goals.Add(goal);
                await _context.SaveChangesAsync();

                return(Created("", goal.Id));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 2
0
        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));
            }
        }