// GET: News public ActionResult Index(NewsSearch search) { var dto = _getNewsCommand.Execute(search); var user = HttpContext.Session.GetObjectFromJson <UserDto>(); return(View(dto)); }
public PagedListNews GetAll([FromBody] NewsSearch newsSearch) { int[] statuses = { News.ACTIVE }; if (!statuses.Contains(newsSearch.Status)) { newsSearch.Status = News.ACTIVE; } newsSearch.UserId = Convert.ToInt32(_httpContextAccessor.HttpContext.User.Identity.Name); var news = _newsService.GetAllByFilter(newsSearch); var metadata = new { news.TotalCount, news.PageSize, news.CurrentPage, news.TotalPages, news.HasNext, news.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); Response.Headers.Add("Access-Control-Expose-Headers", "*"); return(news); }
public IActionResult Get(string searchstring) { SearchString = searchstring; NewsSearch newsSearch = GetNewsSearch(); return(View(newsSearch)); }
public List <Category> Search([FromBody] NewsSearch newsSearch) { int[] statuses = { News.ACTIVE }; if (!statuses.Contains(newsSearch.Status)) { newsSearch.Status = News.ACTIVE; } return(_newsService.Search(newsSearch)); }
public ActionResult <NewsDto> Get([FromQuery] NewsSearch search) { try { var dto = _getNewsCommand.Execute(search); return(Ok(dto)); } catch (EntityNotFoundException) { return(Conflict("There's no data for your request.")); } }
public PageResponse <NewsDto> Execute(NewsSearch request) { var query = Context.News .Include(nc => nc.NewsCategories) .ThenInclude(c => c.Categories).AsQueryable(); if (request.Keyword != null) { query = query.Where(n => n.Heading .ToLower() .Contains(request.Keyword.ToLower())); } if (request.CategoryName != null) { query = query .Where(nc => nc.NewsCategories .Any(cat => cat.Categories.Name.ToLower() .Contains(request.CategoryName.Trim().ToLower()))); } var totalRecords = query.Count(); query = query.Include(u => u.User) .ThenInclude(p => p.Picture) .Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage); var pagesCount = (int)Math.Ceiling((double)totalRecords / request.PerPage); var response = new PageResponse <NewsDto> { CurrentPage = request.PageNumber, TotalCount = totalRecords, PagesCount = pagesCount, Data = query.Select(p => new NewsDto { Id = p.Id, Heading = p.Heading, Content = p.Content, CreatedAt = p.CreatedAt, Username = p.User.Username, Path = p.Pictures == null ? "" : p.Pictures.Where(x => x.NewsId == p.Id).FirstOrDefault().Path, NewsDetail = p.NewsCategories.Select(nd => new NewsDetailsDto { CategoryName = nd.Categories.Name, CategoryId = nd.CategoryId }).ToList() }) }; return(response); }
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([FromBody] NewsSearch newsSearch) { newsSearch.UserId = Convert.ToInt32(_httpContextAccessor.HttpContext.User.Identity.Name); var news = _newsService.GetAllFavourites(newsSearch); var metadata = new { news.TotalCount, news.PageSize, news.CurrentPage, news.TotalPages, news.HasNext, news.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); Response.Headers.Add("Access-Control-Expose-Headers", "*"); return(news); }
public List <Category> Search(NewsSearch newsSearch) { var result = (from news in _context.News join cat in _context.Categories on news.CategoryId equals cat.Id where news.Title.Contains(newsSearch.Title) group news by new { news.CategoryId, cat.Name } into r select new Category { Id = r.Key.CategoryId, Name = r.Key.Name, CountNews = r.Count() }).ToList(); return(result); }
private void FillDatabaseObjects() { WebsiteContext C = GetInMemoryDBWithSeeder(); SearchController SC = new SearchController(C); DatabaseObject Employee = new EmployeeSearch(C); DatabaseObject Product = new ProductSearch(C); DatabaseObject Recipe = new RecipeSearch(C); DatabaseObject News = new NewsSearch(C); Employee.SetObject(C.Employee_Profiles.ToList().ElementAt(0)); Product.SetObject(C.Products.ToList().ElementAt(0)); Recipe.SetObject(C.Recipes.ToList().ElementAt(0)); News.SetObject(C.News_Items.ToList().ElementAt(0)); EmployeeTest = Employee; ProductTest = Product; RecipeTest = Recipe; NewsTest = News; }
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 System.Linq.IQueryable <News> QueryNewsAttributesByCondition(System.Linq.IQueryable <News> news, NewsSearch newsSearch, DataContext _context) { string AttributeConditions = ""; if (newsSearch.Attributes != null && newsSearch.Attributes.Count > 0) { foreach (var attr in newsSearch.Attributes) { if (!string.IsNullOrEmpty(attr.Value)) { AttributeConditions += AttributeConditions + "AND (NewsAttribute.Id = " + attr.AttributeId + " AND NewsAttribute.Value = '" + attr.Value + "')"; } else if (attr.ValueFrom > 0 && attr.ValueTo > 0) { AttributeConditions += AttributeConditions + "AND (NewsAttribute.Id = " + attr.AttributeId + " AND NewsAttribute.Value >= CONVERT(int, " + attr.ValueFrom + ") AND NewsAttribute.Value <= CONVERT(int, " + attr.ValueTo + "))"; } } } if (!string.IsNullOrEmpty(AttributeConditions)) { news = news.Where(AttributeConditions); } return(news); }
PagingObject <News> GetNewsPaging(NewsSearch filter, int pageIndex, int pageSize);
public IActionResult Get() { NewsSearch newsSearch = GetNewsSearch(); return(View(newsSearch)); }
protected IQueryable <News> Query(IQueryable <News> news, NewsSearch newsSearch) { if (newsSearch.Attributes != null && newsSearch.Attributes.Count > 0) { news = from n in news join atr in _context.NewsAttribute on n.Id equals atr.NewsId select n; foreach (var attr in newsSearch.Attributes) { if (!string.IsNullOrEmpty(attr.Value)) { news = from n in news join atr in _context.NewsAttribute on n.Id equals atr.NewsId where atr.AttributeId == attr.AttributeId && atr.Value == attr.Value select n; } else if (attr.ValueFrom > 0 && attr.ValueTo > 0) { news = from n in news join atr in _context.NewsAttribute on n.Id equals atr.NewsId where atr.AttributeId == attr.AttributeId && Convert.ToInt32(atr.Value) >= attr.ValueFrom && Convert.ToInt32(atr.Value) <= attr.ValueTo select n; } else if (attr.ValueFrom > 0) { news = from n in news join atr in _context.NewsAttribute on n.Id equals atr.NewsId where atr.AttributeId == attr.AttributeId && Convert.ToInt32(atr.Value) >= attr.ValueFrom select n; } else if (attr.ValueTo > 0) { news = from n in news join atr in _context.NewsAttribute on n.Id equals atr.NewsId where atr.AttributeId == attr.AttributeId && Convert.ToInt32(atr.Value) <= attr.ValueTo select n; } } } if (newsSearch.Id > 0) { news = news.Where(x => x.Id == newsSearch.Id); } if (newsSearch.CategoryId > 0) { news = news.Where(x => x.CategoryId == newsSearch.CategoryId); } if (!string.IsNullOrEmpty(newsSearch.Title)) { news = news.Where(x => x.Title.Contains(newsSearch.Title)); } if (newsSearch.OwnerId > 0) { news = news.Where(x => x.OwnerId == newsSearch.OwnerId); } int[] statuses = { News.NEW, News.ACTIVE, News.ARCHIVE, News.REJECTED, News.DELETED }; if (statuses.Contains(newsSearch.Status)) { news = news.Where(x => x.Status == newsSearch.Status); } if (newsSearch.Price != null) { if (newsSearch.Price.AmountFrom > 0) { news = news.Where(x => x.Price.Amount >= newsSearch.Price.AmountFrom); } if (newsSearch.Price.AmountTo > 0) { news = news.Where(x => x.Price.Amount <= newsSearch.Price.AmountTo); } if (newsSearch.Price.Currency > 0) { news = news.Where(x => x.Price.Currency == newsSearch.Price.Currency); } } if (newsSearch.Location != null) { if (newsSearch.Location.RegionId > 0) { news = news.Where(x => x.Location.RegionId == newsSearch.Location.RegionId); } if (newsSearch.Location.DistrictId > 0) { news = news.Where(x => x.Location.DistrictId == newsSearch.Location.DistrictId); } if (!string.IsNullOrEmpty(newsSearch.Location.Longtitude)) { news = news.Where(x => x.Location.Longtitude.Contains(newsSearch.Location.Longtitude)); } if (!string.IsNullOrEmpty(newsSearch.Location.Latitude)) { news = news.Where(x => x.Location.Latitude.Contains(newsSearch.Location.Latitude)); } } return(news); }
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)); }