Example #1
0
        public ActionResult Put(Guid userId, Guid id, StickyNoteDto stickyNoteDto)
        {
            var author = _stickyNotes.Users.FirstOrDefault(p => p.Id == userId);

            if (author is null)
            {
                return(NotFound());
            }

            var stickyNote = _stickyNotes.StickyNotes.FirstOrDefault(p => p.Id == id);

            if (stickyNote is null)
            {
                stickyNote = new StickyNote {
                    Title = stickyNoteDto.Title, Note = stickyNoteDto.Note, UserId = userId, Id = id
                };
                _stickyNotes.StickyNotes.Add(stickyNote);
                _stickyNotes.SaveChanges();
                return(CreatedAtAction("Get", new { id = stickyNote.Id, userId }, stickyNote));
            }
            stickyNote.Title = stickyNoteDto.Title;
            stickyNote.Note  = stickyNoteDto.Note;
            _stickyNotes.SaveChanges();
            return(NoContent());
        }
Example #2
0
        public ActionResult Post(Guid userId, StickyNoteDto stickyNoteDto)
        {
            var stickyNote = new StickyNote {
                Title = stickyNoteDto.Title, Note = stickyNoteDto.Note, UserId = userId, Id = Guid.NewGuid()
            };

            _stickyNotes.StickyNotes.Add(stickyNote);
            _stickyNotes.SaveChanges();
            return(CreatedAtAction("Get", new { id = stickyNote.Id, userId }, stickyNote));
        }