Esempio n. 1
0
        public async Task <IActionResult> PutChore(int id, Chore chore)
        {
            if (id != chore.ChoreId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <Chore> > CreateChore(Chore chore)
        {
            _context.Chores.Add(chore);
            _context.Days.AddRange(_days.Select(day => new Day()
            {
                Name    = day,
                ChoreId = chore.Id,
                Status  = "unchecked"
            }));
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetChore), new { id = chore.Id }, chore));
        }
Esempio n. 3
0
 public async Task Post([FromBody] Chore chore)
 {
     _context.Chores.Add(chore);
     await _context.SaveChangesAsync();
 }