示例#1
0
        public JsonResult Delete(int id)
        {
            var target = _postCategoryService.Delete(id);

            _postCategoryService.Save();
            return(Json(new
            {
                message = ResultState.Delete_SUCCESS
            }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public virtual async Task <ActionResult> Delete(int id)
        {
            _categoryService.Delete(id);
            await _unitOfWork.SaveAllChangesAsync();

            return(Json("ok"));
        }
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             _postCategoryService.Delete(id);
             _postCategoryService.Save();
             var identity = (ClaimsIdentity)User.Identity;
             IEnumerable <Claim> claims = identity.Claims;
             Log log = new Log()
             {
                 AppUserId = claims.FirstOrDefault().Value,
                 Content = Notification.DELETE_POSTCATEGORY,
                 Created = DateTime.Now
             };
             _logService.Create(log);
             _logService.Save();
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
 public HttpResponseMessage Delete(HttpRequestMessage requestMessage, int id)
 {
     return(CreateHttpResponse(requestMessage, () =>
     {
         HttpResponseMessage responseMessage = null;
         if (!ModelState.IsValid)
         {
             responseMessage = requestMessage.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var oldData = _postCategoryService.Delete(id);
             _postCategoryService.Save();
             responseMessage = requestMessage.CreateResponse(HttpStatusCode.Created, oldData);
         }
         return responseMessage;
     }));
 }
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             _postCategoryService.Delete(id);
             _postCategoryService.Save();
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
示例#6
0
        [HttpPost("delete")]//
        public IActionResult Delete(PostCategory postCategory)
        {
            var result = _postCategoryService.Delete(postCategory);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
示例#7
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var oldPostCategory = _postCategoryService.Delete(id);
                    _postCategoryService.Save();

                    var responseData = Mapper.Map <PostCategory, PostCategoryViewModel>(oldPostCategory);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }
                return response;
            }));
        }
示例#8
0
 public HttpResponseMessage Delete(HttpRequestMessage request, int id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         _postCategoryService.Delete(id);
         _postCategoryService.Save();
         response = request.CreateResponse(HttpStatusCode.OK, id);
         return response;
     }));
 }
示例#9
0
 public IActionResult Delete(Guid id)
 {
     return(DoActionWithReturnResult(() =>
     {
         bool isDelete = _postCategoryService.Delete(id, CurrentUserId);
         if (isDelete)
         {
             _postCategoryService.Save();
         }
         return Json(isDelete);
     }));
 }
示例#10
0
 public IActionResult Delete(string id)
 {
     try
     {
         _PostCategoryService.Delete(id);
         _PostCategoryService.SaveChange();
         return(Ok());
     }
     catch (Exception ex)
     {
         throw;
     }
 }
 public IHttpActionResult Delete([FromUri] string postId)
 {
     try
     {
         var responseData = _postCategoryService.Delete(postId);
         _postCategoryService.Save();
         return(Ok(responseData));
     }
     catch (Exception ex)
     {
         _logger.LogError("Error at method: Delete - PostCategoryApi," + ex.InnerException.InnerException.Message + "");
         return(BadRequest("Error System"));
     }
 }
 public PostCategoryViewModel Delete(int Id)
 {
     try
     {
         var model = _postCategoryService.Delete(Id);
         _postCategoryService.SaveChanges();
         var res = Mapper.Map <PostCategoryViewModel>(model);
         return(res);
     }
     catch (Exception ex)
     {
         LogError(ex);
         return(null);
     }
 }
示例#13
0
        public HttpResponseMessage Delete(HttpRequestMessage requestMessage, int id)
        {
            return(CreateHttpReponseMessage(requestMessage, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    var category = _postCategoryService.Delete(id);
                    _postCategoryService.SaveChanges();

                    response = requestMessage.CreateResponse(HttpStatusCode.Created, category);
                }
                else
                {
                    requestMessage.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }

                return response;
            }));
        }
示例#14
0
 public HttpResponseMessage Delete(HttpRequestMessage request, PostCategoryViewModel postCategoryViewModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage respone = null;
         if (ModelState.IsValid)
         {
             PostCategory postCategory = new PostCategory();
             postCategory.UpdatePostCategory(postCategoryViewModel);
             var category = _postCategoryService.Delete(postCategory);
             _postCategoryService.SaveChanges();
             respone = request.CreateResponse(HttpStatusCode.OK, category);
         }
         else
         {
             respone = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         return respone;
     }));
 }
示例#15
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    //xuất ra lỗi
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else //nếu thành công thì thêm đối tượng
                {
                    _postCategoryService.Delete(id);
                    _postCategoryService.Save();

                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                return response;
            }));
        }
示例#16
0
        // Xóa
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            return(CreateHttpResponse(request,
                                      () => {
                HttpResponseMessage response = null;
                // kiểm tra ngoại lệ của dữ liệu truyền vào
                if (ModelState.IsValid)
                {
                    // nếu có lỗi thì truyền lỗi đó vào bảng lỗi trong database
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    // không có lỗi sẽ dùng  Service để lưu đối tượng vào database
                    _postCategoryService.Delete(id);

                    try
                    {
                        _postCategoryService.Save();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }

                    // trả về đối tượng đã dược lưu để xử lý
                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                return response;
            }));
        }
示例#17
0
        public ActionResult Delete(int postCategoryId)
        {
            _postCategoryService.Delete(postCategoryId);

            return(RedirectToAction("Index", "BlogManager"));
        }
示例#18
0
 protected internal async Task <bool> DeletePostCategoryAsync(Guid postCategoryId)
 {
     CheckIfIdIsCorrectFormat(postCategoryId);
     return(await _postCategoryService.Delete(postCategoryId));
 }
示例#19
0
 public IActionResult Delete(int id)
 {
     if (!ModelState.IsValid)
     {
         return(new BadRequestObjectResult(ModelState));
     }
     else
     {
         var subListL2 = _postCategoryService.AllSubCategories(id);
         if (subListL2 != null)
         {
             foreach (var itemL2 in subListL2)
             {
                 var subListL3 = _postCategoryService.AllSubCategories(itemL2.Id);
                 if (subListL3 != null)
                 {
                     foreach (var itemL3 in subListL3)
                     {
                         var subListL4 = _postCategoryService.AllSubCategories(itemL3.Id);
                         if (subListL4 != null)
                         {
                             foreach (var itemL4 in subListL4)
                             {
                                 var subListL5 = _postCategoryService.AllSubCategories(itemL4.Id);
                                 if (subListL5 != null)
                                 {
                                     foreach (var itemL5 in subListL5)
                                     {
                                         var subListL6 = _postCategoryService.AllSubCategories(itemL5.Id);
                                         if (subListL6 != null)
                                         {
                                             foreach (var itemL6 in subListL6)
                                             {
                                                 var lstIdL6 = _postService.GetIds(itemL6.Id);
                                                 _postService.MultiDelete(lstIdL6);
                                                 _postCategoryService.Delete(itemL6.Id);
                                                 _postService.Save();
                                             }
                                         }
                                         var lstIdL5 = _postService.GetIds(itemL5.Id);
                                         _postService.MultiDelete(lstIdL5);
                                         _postCategoryService.Delete(itemL5.Id);
                                         _postService.Save();
                                     }
                                 }
                                 var lstIdL4 = _postService.GetIds(itemL4.Id);
                                 _postService.MultiDelete(lstIdL4);
                                 _postCategoryService.Delete(itemL4.Id);
                                 _postService.Save();
                             }
                         }
                         var lstIdL3 = _postService.GetIds(itemL3.Id);
                         _postService.MultiDelete(lstIdL3);
                         _postCategoryService.Delete(itemL3.Id);
                         _postService.Save();
                     }
                 }
                 var lstIdL2 = _postService.GetIds(itemL2.Id);
                 _postService.MultiDelete(lstIdL2);
                 _postCategoryService.Delete(itemL2.Id);
                 _postService.Save();
             }
         }
         var lstIdL1 = _postService.GetIds(id);
         _postService.MultiDelete(lstIdL1);
         _postService.Save();
         _postCategoryService.Delete(id);
         _postCategoryService.Save();
         return(new OkObjectResult(id));
     }
 }