public async Task<IActionResult> Create([FromBody] CreateTrackerLogViewModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } TrackerLog trackerLog = new TrackerLog { Message= model.Message, CreationDate = DateTime.Now }; _context.TrackerLogs.Add(trackerLog); try { await _context.SaveChangesAsync(); Int64 id = trackerLog.Id; } catch (Exception ex) { return BadRequest(); } return Ok(trackerLog); }
public async Task<IActionResult> PutTrackerLog([FromRoute] Int64 id, [FromBody] TrackerLog trackerLog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != trackerLog.Id) { return BadRequest(); } _context.Entry(trackerLog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrackerLogExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }