Ejemplo n.º 1
0
        public async Task <IActionResult> PutGoal(int id, [FromForm] GoalUpsert obj)
        {
            Goal goal = await _context.Goal.FirstOrDefaultAsync(x => x.ID == id);

            goal = viewModel.Update(goal, obj);

            _context.Entry(goal).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GoalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Goal> > PostGoal([FromForm] GoalUpsert obj)
        {
            if (ModelState.IsValid)
            {
                Goal goal = viewModel.Add(obj);
                _context.Goal.Add(goal);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetGoal", new { id = goal.ID }, goal));
            }
            else
            {
                return(ValidationProblem());
            }
        }