public ICollection <VisualizeScooterViewModel> GetOnlyUserScooters(string userId, FiltersInputModel filtersInput) { var scooterOffersToVisualize = new List <VisualizeScooterViewModel>(); var filtersQuery = GetFiltersAsQuery(filtersInput); var scooterOffers = dbContext.ElectricScooterOffers.FromSqlRaw( "select * from ElectricScooterOffers " + $"where {filtersQuery}") .ToList(); foreach (var scooterOffer in scooterOffers.Where(x => x.UserId == userId)) { var scooter = new VisualizeScooterViewModel() { Id = scooterOffer.Id, Title = scooterOffer.Title, Condition = scooterOffer.Condition.ToString(), Year = scooterOffer.Year, Price = scooterOffer.Price, Kilometers = scooterOffer.Kilometers, MotorPower = scooterOffer.MotorPower, WaterproofLevel = scooterOffer.WaterproofLevel, Battery = scooterOffer.Battery }; scooter.Image = ConvertByteArrayToImage(scooterOffer.OfferImage); scooterOffersToVisualize.Add(scooter); } return(scooterOffersToVisualize); }
public ICollection <VisualizeScooterViewModel> ScootersForVisualization() { var scooterOffersToVisualize = new List <VisualizeScooterViewModel>(); foreach (var scooterOffer in dbContext.ElectricScooterOffers.ToArray()) { var scooter = new VisualizeScooterViewModel() { Id = scooterOffer.Id, Title = scooterOffer.Title, Condition = scooterOffer.Condition.ToString(), Year = scooterOffer.Year, Price = scooterOffer.Price, Kilometers = scooterOffer.Kilometers, MotorPower = scooterOffer.MotorPower, WaterproofLevel = scooterOffer.WaterproofLevel, Battery = scooterOffer.Battery }; scooter.Image = ConvertByteArrayToImage(scooterOffer.OfferImage); scooterOffersToVisualize.Add(scooter); } return(scooterOffersToVisualize); }
public ICollection <VisualizeScooterViewModel> ScootersForVisualization(string sortingType) { var scooterOffersToVisualize = new List <VisualizeScooterViewModel>(); var scooterOffers = dbContext.ElectricScooterOffers.ToList(); if (sortingType == "UploadDate") { scooterOffers = scooterOffers.OrderByDescending(x => x.CreatedOn).ToList(); } else if (sortingType == "LowestPrice") { scooterOffers = scooterOffers.OrderBy(x => x.Price).ToList(); } else if (sortingType == "HighestPrice") { scooterOffers = scooterOffers.OrderByDescending(x => x.Price).ToList(); } else if (sortingType == "OldestYear") { scooterOffers = scooterOffers.OrderBy(x => x.Year).ToList(); } else if (sortingType == "NewestYear") { scooterOffers = scooterOffers.OrderByDescending(x => x.Year).ToList(); } foreach (var scooterOffer in scooterOffers) { var scooter = new VisualizeScooterViewModel() { Id = scooterOffer.Id, Title = scooterOffer.Title, Condition = scooterOffer.Condition.ToString(), Year = scooterOffer.Year, Price = scooterOffer.Price, Kilometers = scooterOffer.Kilometers, MotorPower = scooterOffer.MotorPower, WaterproofLevel = scooterOffer.WaterproofLevel, Battery = scooterOffer.Battery }; scooter.Image = ConvertByteArrayToImage(scooterOffer.OfferImage); scooterOffersToVisualize.Add(scooter); } return(scooterOffersToVisualize); }