public PagedListNews GetAllByTariff(NewsSearch newsSearch) { int[] tariffs = { Tariff.MAIN, Tariff.VIP, Tariff.TOP }; if (!tariffs.Contains(newsSearch.Type)) { throw new AppException("Wrong Tariff Type"); } var news = from n in _context.News join tariff in _context.Tariff on n.Id equals tariff.NewsId where tariff.Type == newsSearch.Type && tariff.ExpireDate >= DateHelper.GetDate() join fav in _context.UserFavourites on n.Id equals fav.NewsId into gj from fav in gj.Where(x => x.UserId == newsSearch.UserId).DefaultIfEmpty() join i in _context.Images on n.Id equals i.NewsId into i from images in i.DefaultIfEmpty() select new News() { Id = n.Id, Title = n.Title, CategoryId = n.CategoryId, Category = n.Category, PriceId = n.PriceId, Price = n.Price, Description = n.Description, LocationId = n.LocationId, Location = n.Location, ContactDetailId = n.ContactDetailId, ContactDetail = n.ContactDetail, Status = n.Status, CreatedDate = n.CreatedDate, UpdatedDate = n.UpdatedDate, OwnerId = n.OwnerId, Images = _context.Images.Where(x => x.NewsId == n.Id).ToList(), Favourite = fav == null ? false : true, }; news = Query(news, newsSearch); news = news.GroupBy(item => item.Id).Select(group => group.FirstOrDefault()); return(PagedListNews.ToPagedList(news, newsSearch.PageNumber, newsSearch.PageSize, _context)); }
public PagedListNews GetAllFavourites(NewsSearch newsSearch) { var news = from n in _context.News join fav in _context.UserFavourites on n.Id equals fav.NewsId where fav.UserId == newsSearch.UserId join i in _context.Images on n.Id equals i.NewsId into i from images in i.DefaultIfEmpty() select new News() { Id = n.Id, Title = n.Title, CategoryId = n.CategoryId, Category = n.Category, PriceId = n.PriceId, Price = n.Price, Description = n.Description, LocationId = n.LocationId, Location = n.Location, ContactDetailId = n.ContactDetailId, ContactDetail = n.ContactDetail, Status = n.Status, CreatedDate = n.CreatedDate, UpdatedDate = n.UpdatedDate, OwnerId = n.OwnerId, Images = i == null ? new List <Image>() : i.ToList(), Favourite = true, }; news = Query(news, newsSearch); news = news.GroupBy(item => item.Id).Select(group => group.FirstOrDefault()); return(PagedListNews.ToPagedList(news, newsSearch.PageNumber, newsSearch.PageSize, _context)); }
public PagedListNews GetAllByFilter(NewsSearch newsSearch) { var news = from n in _context.News join u in _context.Users on n.OwnerId equals u.Id join fav in _context.UserFavourites on n.Id equals fav.NewsId into gj from fav in gj.Where(x => x.UserId == newsSearch.UserId).DefaultIfEmpty() join vfav in _context.VendorFavourite on n.OwnerId equals vfav.TargetUserId into vf from vfav in vf.Where(x => x.UserId == newsSearch.UserId).DefaultIfEmpty() join p in _context.UserProfile on n.OwnerId equals p.UserId into p from profile in p.DefaultIfEmpty() join f in _context.ExternalLogin on n.OwnerId equals f.UserId into f from facebook in f.DefaultIfEmpty() join i in _context.Images on n.Id equals i.NewsId into i from images in i.DefaultIfEmpty() join vr in _context.VendorReviews on u.Id equals vr.TargetUserId into vr from vrs in vr.DefaultIfEmpty() join tariff in _context.Tariff on n.Id equals tariff.NewsId into tariff from tariffs in tariff.Where(x => x.ExpireDate >= DateHelper.GetDate()).DefaultIfEmpty() select new News() { Id = n.Id, Title = n.Title, CategoryId = n.CategoryId, Category = n.Category, PriceId = n.PriceId, Price = n.Price, Description = n.Description, LocationId = n.LocationId, Location = n.Location, ContactDetailId = n.ContactDetailId, ContactDetail = n.ContactDetail, Status = n.Status, CreatedDate = n.CreatedDate, UpdatedDate = n.UpdatedDate, OwnerId = n.OwnerId, Images = i == null ? new List <Image>() : i.ToList(), Favourite = fav == null ? false : true, VendorFavourite = vfav == null ? false : true, Tariffs = tariff.ToList(), OwnerDetails = new UserProfile() { UserId = u.Id, UserCreatedAt = u.CreatedDate, Name = profile != null ? (profile.Name != null ? profile.Name : u.FullName) : u.FullName, Surname = profile != null ? (profile.Surname != null ? profile.Surname : u.FullName) : u.FullName, Email = profile != null ? (profile.Email != null ? profile.Email : u.Email) : u.Email, Phone = profile != null ? (profile.Phone != null ? profile.Phone : u.Phone) : u.Phone, FacebookId = facebook != null ? facebook.ClientId : null, Longtitude = profile != null ? profile.Longtitude : null, Latitude = profile != null ? profile.Latitude : null, RegionId = profile != null ? profile.RegionId : 0, DistrictId = profile != null ? profile.DistrictId : 0, CreatedDate = profile != null ? profile.CreatedDate : DateHelper.GetDate(), UpdatedDate = profile != null ? profile.UpdatedDate : DateHelper.GetDate(), Rating = vr.DefaultIfEmpty().Average(c => Convert.ToInt32(c.Mark)).ToString() }, }; news = Query(news, newsSearch); news = news.GroupBy(item => item.Id).Select(group => group.FirstOrDefault()); return(PagedListNews.ToPagedList(news, newsSearch.PageNumber, newsSearch.PageSize, _context)); }