Пример #1
0
 public HttpResponseMessage Get(HttpRequestMessage request, string postId)
 {
     return(CreateHttpResponse(request, () =>
     {
         try
         {
             IEnumerable <PostImage> listPostImageDb = _postImageService.getAllByPostId(postId);
             IEnumerable <PostImageViewModel> listPostImageVm = Mapper.Map <IEnumerable <PostImageViewModel> >(listPostImageDb);
             return request.CreateResponse(HttpStatusCode.OK, listPostImageVm);
         }
         catch
         {
             return request.CreateResponse(HttpStatusCode.BadRequest, "Chưa có ảnh nào");
         }
     }));
 }
Пример #2
0
        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;
            }));
        }