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 Create(HttpRequestMessage request, BaiViet baiViet) { BaiViet modelBaiViet = null; try { baiViet.NgayDang = DateTime.Now; baiViet.TrangThai = true; baiViet.SoCmt = 0; baiViet.SoLike = 0; modelBaiViet = _baiVietService.Add(baiViet); if (modelBaiViet != null) { Message = "Tạo mới Bài Viet thành công"; _baiVietService.SaveChange(); } else { throw new DbEntityValidationException("tạo Bài Viet không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelBaiViet)); }