Exemplo n.º 1
0
        public IActionResult Put(int id, [FromBody] NoteJsonModel model)
        {
            if (!repository.ContainsKey(id))
            {
                return(NotFound());
            }

            CreateOrUpdate(id, model);

            return(StatusCode(200));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }