public async Task <IActionResult> PutActiveLaundry([FromRoute] int id, [FromBody] ActiveLaundry activeLaundry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != activeLaundry.Id) { return(BadRequest()); } _context.Entry(activeLaundry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActiveLaundryExists(id)) { return(NotFound()); } else { throw; } } return(Ok(activeLaundry)); }
public async Task <IActionResult> PostActiveLaundry([FromBody] CreateActiveLaundryViewModel viewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var activeLaundry = new ActiveLaundry { UserId = GetCurrentUserId(), LaundryTemplateId = viewModel.LaundryTemplateId, WashStartTime = viewModel.WashStartTime, Completed = false }; _context.ActiveLaundries.Add(activeLaundry); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetActiveLaundry), new { id = activeLaundry.Id }, activeLaundry)); }