Beispiel #1
0
        public async Task <IActionResult> PutComments([FromRoute] int id, [FromBody] Comment comments)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comments.CommentId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> PutUserInfo([FromRoute] int id, [FromBody] UserinfoDTO userInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userInfo.UserInfoID)
            {
                return(BadRequest());
            }
            UserInfo editedUser = AutoMapper.Mapper.Map <UserinfoDTO, UserInfo>(userInfo);

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

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

            return(NoContent());
        }
Beispiel #3
0
        public async Task <IActionResult> PutPost([FromRoute] int id, [FromBody] PostDTO post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != post.PostId)
            {
                return(BadRequest());
            }
            if (post.PostingUserID > 0)
            {
                post.PostingUser = AutoMapper.Mapper.Map <UserInfo, UserinfoDTO>(_context.UserInfos.FirstOrDefault(u => u.UserInfoID == post.PostingUserID));
            }
            Post editedPost = AutoMapper.Mapper.Map <PostDTO, Post>(post);

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

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

            return(NoContent());
        }