Esempio n. 1
0
        public async Task <IActionResult> PutGuestBook([FromRoute] int id, [FromBody] GuestBook guestBook)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != guestBook.GuestBookId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutUser([FromRoute] string id, [FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutPost([FromRoute] string id, [FromBody] Post post)
        {
            var putPost = await _context.Posts.FindAsync(id);

            putPost.Title   = post.Title;
            putPost.Content = post.Content;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != putPost.PostId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }