public void SetFilterValues(SellFilter search) { this.Search = search.Search; this.StartDate = search.StartDate == null ? "" : search.StartDate.ToString(); this.EndDate = search.EndDate == null ? "" : search.EndDate.ToString(); this.OnlyInName = (bool)search.OnlyInName == null ? "" : search.OnlyInName == true ? "on" : ""; this.StartPrice = search.StartPrice == null ? "" : search.StartPrice.ToString(); this.EndPrice = search.EndPrice == null ? "" : search.StartPrice.ToString(); this.City = search.City; this.SortBy = search.SortBy; }
public static int GetAdvertsActiveCount(SellFilter filter) { using (var ctx = new RentooloEntities()) { if (!string.IsNullOrEmpty(filter.Search)) { int count = ctx.Adverts.Where(x => x.Name.Contains(filter.Search) || x.Description.Contains(filter.Search)).Count(); return(count); } else { int count = ctx.Adverts.Count(); return(count); } } }
public static List <Adverts> GetAdvertsForMainPage(SellFilter filter) { using (var ctx = new RentooloEntities()) { if (!string.IsNullOrEmpty(filter.Search)) { var list = ctx.Adverts.Where(x => x.Name.Contains(filter.Search) || x.Description.Contains(filter.Search)).OrderByDescending(x => x.Created).ToList(); return(list); } else { var list = ctx.Adverts.OrderByDescending(x => x.Created).ToList(); return(list); } } }
public static int GetActiveCount <TEntity>(SellFilter filter = null) where TEntity : class { using (var ctx = new RentooloEntities()) { var items = (DbSet <TEntity>)ctx.GetType().GetProperty(typeof(TEntity).Name).GetValue(ctx); if (!string.IsNullOrEmpty(filter?.Search)) { var count = items.AsEnumerable().Where(x => typeof(TEntity).GetProperty("Name").GetValue(x).ToString(). Contains(filter.Search) || typeof(TEntity).GetProperty("Description").GetValue(x).ToString(). Contains(filter.Search)).Count(); return(count); } else { return(items.Count()); } } }
public static List <Adverts> GetAdvertsForMainPage(SellFilter filter) { // bool isEndDate is needed to undestand correctly startEndDate variable - if its true // it means that startEndDate is endDate else startDate using (var ctx = new RentooloEntities()) { var result = ctx.Adverts.Select(x => x); if (filter.Search != null) { if (filter.OnlyInName) { //result = result.filterAdverts(filter.Search,true); result = result.Where(x => x.Name.Contains(filter.Search)); } else { //result = result.filterAdverts(filter.Search, false); result = result.Where(x => x.Name.Contains(filter.Search) || x.Description.Contains(filter.Search)); } } if (filter.StartDate != null) { //result = result.filterAdverts((DateTime)filter.StartDate, false); result = result.Where(x => x.Created >= filter.StartDate); } if (filter.EndDate != null) { //result = result.filterAdverts((DateTime)filter.EndDate, true); result = result.Where(x => x.Created <= filter.EndDate); } if (filter.StartPrice != null) { //result = result.filterAdverts((double)filter.StartPrice, true); result = result.Where(x => x.Price >= (double)filter.StartPrice); } if ((filter.EndPrice != null) && (filter.EndPrice >= filter.StartPrice)) { //result = result.filterAdverts((double)filter.EndPrice, false); result = result.Where(x => x.Price <= (double)filter.EndPrice); } if (filter.City != null) { //result = result.filterAdverts(filter.City); result = result.Where(x => x.Address.Contains(filter.City)); } switch (filter.SortBy) { case "date": result = result.OrderBy(x => x.Created); break; case "price": result = result.OrderBy(x => x.Price); break; case "date_desc": result = result.OrderByDescending(x => x.Created); break; case "price_desc": result = result.OrderByDescending(x => x.Price); break; default: result = result.OrderBy(x => x.Created); break; } return(result.ToList()); } }