public async Task <IActionResult> PutToiletLog([FromRoute] int id, [FromBody] ToiletLog toiletLog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != toiletLog.ToiletLogId) { return(BadRequest()); } _context.Entry(toiletLog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToiletLogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostToiletLog([FromBody] ToiletLog toiletLog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.ToiletLogs.Add(toiletLog); await _context.SaveChangesAsync(); return(CreatedAtAction("GetToiletLog", new { id = toiletLog.ToiletLogId }, toiletLog)); }
public async Task <IActionResult> PostToiletLog([FromBody] CustomModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var toiletLog = new ToiletLog { ToiletId = model.ToiletId, CleanerId = _context.Cleaners.Where(c => c.Rfid == model.Rfid).Select(c => c.CleanerId).FirstOrDefault(), StartDate = model.StartDate, EndDate = model.EndDate, Duration = model.Duration }; _context.ToiletLogs.Add(toiletLog); await _context.SaveChangesAsync(); return(CreatedAtAction("GetToiletLog", new { id = toiletLog.ToiletLogId }, toiletLog)); }