public List <PostDTO> GetSearchPost(string searchText)
        {
            List <PostDTO> dtolist = new List <PostDTO>();
            var            list    = (from p in db.Posts.Where(x => x.isDeleted == false && (x.Title.Contains(searchText) || x.PostContent.Contains(searchText)))
                                      join c in db.Categories on p.CategoryID equals c.ID
                                      select new
            {
                postID = p.ID,
                title = p.Title,
                categoryName = c.CategoryName,
                seolink = p.SeoLink,
                viewcount = p.ViewCount,
                Adddate = p.AddDate
            }

                                      ).OrderByDescending(x => x.Adddate).ToList();

            foreach (var item in list)
            {
                PostDTO dto = new PostDTO();
                dto.ID           = item.postID;
                dto.Title        = item.title;
                dto.CategoryName = item.categoryName;
                dto.ViewCount    = item.viewcount;
                dto.SeoLink      = item.seolink;
                PostImage image = db.PostImages.First(x => x.isDeleted == false && x.PostID == item.postID);
                dto.ImagePath    = image.ImagePath;
                dto.CommentCount = db.Comments.Where(x => x.isDeleted == false && x.PostID == item.postID && x.isApproved == true).Count();
                dto.AddDate      = item.Adddate;
                dtolist.Add(dto);
            }
            return(dtolist);
        }
        public List <PostDTO> GetCategoryPostList(int categoryID)
        {
            List <PostDTO> dtoList = new List <PostDTO>();
            var            list    = (from p in db.Posts.Where(x => x.CategoryID == categoryID && x.isDeleted == false)
                                      select new
            {
                postID = p.ID,
                title = p.Title,
                categoryName = p.Category.CateogryName,
                seoLink = p.SeoLink,
                viewCount = p.ViewCount,
                addDate = p.AddDate
            }).OrderByDescending(x => x.addDate).ToList();

            foreach (var item in list)
            {
                PostDTO dto = new PostDTO();
                dto.ID           = item.postID;
                dto.Title        = item.title;
                dto.CategoryName = item.categoryName;
                dto.ViewCount    = item.viewCount;
                dto.SeoLink      = item.seoLink;
                PostImage image = db.PostImages.First(x => x.isDeleted == false && x.PostID == item.postID);
                dto.ImagePath    = image.ImagePath;
                dto.CommentCount = db.Comments.Where(x => x.isDeleted == false && x.PostID == item.postID && x.isApproved == true).Count();
                dto.AddDate      = item.addDate;
                dtoList.Add(dto);
            }
            return(dtoList);
        }
Exemple #3
0
 public int AddImage(PostImage image)
 {
     try
     {
         using (POSTDATAEntities db = new POSTDATAEntities())
         {
             db.PostImages.Add(image);
             db.SaveChanges();
         }
         return(image.ID);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public string DeletePostImage(int ID)
 {
     try
     {
         string imagePath = "";
         using (POSTDATAEntities db = new POSTDATAEntities())
         {
             PostImage img = db.PostImages.First(x => x.ID == ID);
             imagePath            = img.ImagePath;
             img.isDeleted        = true;
             img.DeletedDate      = DateTime.Now;
             img.LastUpdateDate   = DateTime.Now;
             img.LastUpdateUserID = UserStatic.UserID;
             db.SaveChanges();
         }
         return(imagePath);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }