Example #1
0
        public HttpResponseMessage GetAllByIdChuyenMuc(HttpRequestMessage request, int id)
        {
            IEnumerable <BaiViet> listLike = null;
            var toTal = 0;

            try
            {
                listLike = _baiVietService.BaiVietWithIdChuyenMuc(id);
                toTal    = listLike.ToList().Count;
                if (toTal
                    > 0)
                {
                    Message = "Danh sách bài viết cua chuyên mục";
                }
                else
                {
                    throw new DbEntityValidationException("Không tồn tại danh sách bài viết của chuyên mục nào");
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, toTal, listLike));
        }
Example #2
0
        public HttpResponseMessage Delete(HttpRequestMessage request, int id)
        {
            ChuyenMuc modelChuyenMuc = null;

            try
            {
                var listBaiViet = _baiVietService.BaiVietWithIdChuyenMuc(id);
                foreach (var item in listBaiViet)
                {
                    var listBinhLuan = _binhLuanService.BinhLuanWithIdBaiViet(id);
                    foreach (var item2 in listBinhLuan)
                    {
                        _binhLuanService.Delete(item2.IdBinhLuan);
                    }
                    _chuyenMucService.SaveChange();
                    _baiVietService.Delete(item.IdBaiViet);
                }
                _chuyenMucService.SaveChange();
                modelChuyenMuc = _chuyenMucService.Delete(id);
                _chuyenMucService.SaveChange();
                if (modelChuyenMuc != null)
                {
                    Message = "Xóa chuyên mục thành công";
                }
                else
                {
                    throw new DbEntityValidationException("Xóa chuyên mục không thành công");
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, modelChuyenMuc));
        }