public async Task <IActionResult> PutHabitsCategory([FromRoute] int id, [FromBody] HabitsCategory habitsCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != habitsCategory.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Habit> > Post(Habit habit)
        {
            _context.Habits.Add(habit);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = habit.Id }, habit));
        }