public IHttpActionResult ThemBaiViet_Tuong(TinTucModel tinTuc) { NEWSTUONG_BaiViet tin = new NEWSTUONG_BaiViet(); tin.Title = tinTuc.TieuDe; tin.Content = tinTuc.NoiDung; tin.TotalView = 0; tin.CreatedUserId = 56; tin.CreatedUser = "******"; tin.CreatedDate = tinTuc.NgayTao; tin.IsApproved = tinTuc.HienThi; tin.IsFavorit = tinTuc.TinNoiBat; dbContext.NEWSTUONG_BaiViet.Add(tin); dbContext.SaveChanges(); if (tinTuc.TapTinDinhKem.Count > 0) { foreach (var item in tinTuc.TapTinDinhKem) { NEWSTUONG_TinDinhKem tttt = new NEWSTUONG_TinDinhKem(); tttt.FileName = item.Ten; tttt.FileSize = item.Size; tttt.PostId = tin.PostId; tttt.CreatedDate = DateTime.Now; dbContext.NEWSTUONG_TinDinhKem.Add(tttt); dbContext.SaveChanges(); } } return(Ok("Thêm Bài Viết Thành Công")); }
public IHttpActionResult CapNhatFileTuong(TapTinModel taptin) { NEWSTUONG_TinDinhKem tapTinDinhKem = new NEWSTUONG_TinDinhKem(); tapTinDinhKem.FileName = taptin.Ten; tapTinDinhKem.FileSize = taptin.Size; tapTinDinhKem.OriginalFilename = taptin.Ten; tapTinDinhKem.PostId = taptin.MaTinTuc; tapTinDinhKem.UserId = 56; tapTinDinhKem.CreatedDate = DateTime.Now; dbContext.NEWSTUONG_TinDinhKem.Add(tapTinDinhKem); dbContext.SaveChanges(); return(Ok(tapTinDinhKem.FileId)); }
public IHttpActionResult ChiaSeBaiViet(TinTucModel tinTuc) { var bv = dbContext.NEWS_TinTuc.Where(x => x.MaTinTuc == tinTuc.MaTinTuc).FirstOrDefault(); if (bv != null) { bv.ChiaSe = false; dbContext.SaveChanges(); NEWSTUONG_BaiViet bvt = new NEWSTUONG_BaiViet(); bvt.ParentId = 0; bvt.GroupId = 13; bvt.ReplyToId = 0; bvt.Title = tinTuc.TieuDe; bvt.Content = tinTuc.NoiDung; bvt.TotalReplies = 0; bvt.TotalView = 13; bvt.ShareID = tinTuc.MaTinTuc; bvt.CreatedUserId = 56; bvt.CreatedUser = "******"; bvt.CreatedDate = DateTime.Now; bvt.LastPost = null; bvt.LastPostId = null; bvt.LastUpdated = null; bvt.LastUpdatedUser = null; bvt.LastUpdatedUserId = null; bvt.IsApproved = false; bvt.IsFavorit = false; dbContext.NEWSTUONG_BaiViet.Add(bvt); dbContext.SaveChanges(); if (tinTuc.TapTinDinhKem.Count > 0) { try { foreach (var item in tinTuc.TapTinDinhKem) { NEWSTUONG_TinDinhKem ttdk = new NEWSTUONG_TinDinhKem(); ttdk.FileName = item.Ten.Trim(); ttdk.OriginalFilename = item.Ten.Trim(); ttdk.FileSize = "256"; ttdk.GroupId = bvt.GroupId; ttdk.UserId = bvt.CreatedUserId; ttdk.PostId = bvt.PostId; ttdk.CreatedDate = bvt.CreatedDate; dbContext.NEWSTUONG_TinDinhKem.Add(ttdk); dbContext.SaveChanges(); } } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } return(Ok("Bài Viết Đang Chờ Duyệt Để Được Chia Sẻ Lên Tường")); } return(BadRequest("Có Lỗi Phát Sinh,Xin Vui Lòng Thử Lại")); }