public HttpResponseMessage Create(HttpRequestMessage request, PostImageViewModel postImageVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { PostImage postImageDb = new PostImage(); postImageDb.UpdatePostImage(postImageVm); _postImageService.Add(postImageDb); _postImageService.SaveChange(); return request.CreateResponse(HttpStatusCode.OK, postImageVm); } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
public HttpResponseMessage Delete(HttpRequestMessage request, string id) { HttpResponseMessage response = null; return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { //deleteElementImage IEnumerable <PostImage> listPostImage = _postImageService.getAllByPostId(id); foreach (var item in listPostImage) { DeleteElementImage(item.Path); } //delete ThubnailImage if (_postService.GetById(id).Image != null) { DeleteElementImage(_postService.GetById(id).Image.ToString()); } //deletePostImage _postImageService.DeleteMultiByPostId(id); _postImageService.SaveChange(); //delete post _postService.Delete(id); _postService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.OK, id); } else { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } return response; })); }