Example #1
0
        public async Task <ActionResult <ManagedNotesDTO> > PostManagedNotes(ManagedNotesDTO managedNotesDTO)
        {
            var managedNotes = new ManagedNotes
            {
                IsComplete = managedNotesDTO.IsComplete,
                Name       = managedNotesDTO.Name
            };

            _context.Notes.Add(managedNotes);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetManagedNotes), new { id = managedNotesDTO.Id }, managedNotesDTO));
            //return CreatedAtAction("GetManagedNotes", new { id = managedNotes.Id }, managedNotes);
        }
Example #2
0
        public async Task <IActionResult> PutManagedNotes(long id, ManagedNotesDTO managedNotesDTO)
        {
            if (id != managedNotesDTO.Id)
            {
                return(BadRequest());
            }

            var managedNotes = await _context.Notes.FindAsync(id);

            if (managedNotes == null)
            {
                return(NotFound());
            }

            managedNotes.IsComplete = managedNotesDTO.IsComplete;
            managedNotes.Name       = managedNotesDTO.Name;

            _context.Entry(managedNotes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ManagedNotesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }