public HttpResponseMessage Create(HttpRequestMessage request, BinhLuan binhLuan) { BinhLuan modelBinhLuan = null; try { binhLuan.NgayBinhLuan = DateTime.Now; binhLuan.TrangThai = true; binhLuan.SoLike = 0; modelBinhLuan = _binhLuanService.Add(binhLuan); _binhLuanService.SaveChange(); if (modelBinhLuan != null) { if (binhLuan.IdBaiViet != null) { var baiViet = _baiVietService.GetById((int)binhLuan.IdBaiViet); baiViet.SoCmt++; _baiVietService.SaveChange(); } Message = "Tạo mới bình luận thành công"; } else { throw new DbEntityValidationException("tạo mới bình luận không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelBinhLuan)); }
public HttpResponseMessage GetAll(HttpRequestMessage request, int id) { BaiViet baiViet = null; try { baiViet = _baiVietService.GetById(id); if (baiViet != null) { Message = "thông tin bài viết"; } else { throw new DbEntityValidationException(string.Format("Không tồn tại bài viết với id {0}", id)); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, baiViet)); }