public IActionResult Put(int id, [FromBody] NoteJsonModel model) { if (!repository.ContainsKey(id)) { return(NotFound()); } CreateOrUpdate(id, model); return(StatusCode(200)); }
public IActionResult Post([FromBody] NoteJsonModel model) { if (model.Content == null) { return(StatusCode(500)); } var note = CreateOrUpdate(currentId++, model); var data = Convert(note); return(new JsonResult(data)); }
private Note CreateOrUpdate(int id, NoteJsonModel model) { var note = repository.ContainsKey(id) ? repository[id] : new Note { Id = id }; note.Title = model.Title ?? note.Title; note.Content = model.Content ?? note.Content; if (repository.ContainsKey(id)) { repository.Remove(id); } repository.Add(id, note); return(note); }