Пример #1
0
        public async Task GetCinemas()
        {
            var allCinemas = await _cinemasAPI.Get <List <Model.Cinema> >(null);

            allCinemas.Sort((a, b) => a.Name.CompareTo(b.Name));

            if (SelectedLocation != null)
            {
                Model.Requests.CinemasSearchRequest search = new Model.Requests.CinemasSearchRequest()
                {
                    Location = SelectedLocation
                };

                var c = new List <Model.Cinema>();
                if (SelectedLocation == "All")
                {
                    c = await _cinemasAPI.Get <List <Model.Cinema> >(null);
                }
                else
                {
                    c = await _cinemasAPI.Get <List <Model.Cinema> >(search);
                }
                c.Sort((a, b) => a.Name.CompareTo(b.Name));
                Cinemas.Clear();

                foreach (var cinema in c)
                {
                    Cinemas.Add(cinema);
                }
            }

            if (Locations.Count == 0)
            {
                var list = new List <string>();
                list.Add("All");
                foreach (var cinema in allCinemas)
                {
                    list.Add(cinema.Location);
                }
                list = list.Distinct().ToList();
                list.Sort();
                foreach (var location in list)
                {
                    Locations.Add(location);
                }
            }
        }
Пример #2
0
        public List <Model.Cinema> Get(Model.Requests.CinemasSearchRequest request)
        {
            var query = _context.Cinemas.AsQueryable();

            if (!string.IsNullOrWhiteSpace(request?.Name))
            {
                query = query.Where(c => c.Name.ToLower().StartsWith(request.Name.ToLower()));
            }
            if (!string.IsNullOrWhiteSpace(request?.Address))
            {
                query = query.Where(c => c.Address.ToLower().StartsWith(request.Address.ToLower()));
            }
            if (!string.IsNullOrWhiteSpace(request?.Location))
            {
                query = query.Where(c => c.Location.ToLower().StartsWith(request.Location.ToLower()));
            }
            if (request?.Rating >= 0)
            {
                query = query.Where(c => c.Rating >= request.Rating);
            }

            return(_mapper.Map <List <Model.Cinema> >(query.ToList()));
        }
Пример #3
0
 public ActionResult <List <Model.Cinema> > Get([FromQuery] Model.Requests.CinemasSearchRequest request)
 {
     return(_service.Get(request));
 }