Exemplo n.º 1
0
 public List <TourViewModel> Read(TourBindingModel model)
 {
     if (model == null)
     {
         return(_tourStorage.GetFullList());
     }
     if (model.ID.HasValue)
     {
         return(new List <TourViewModel> {
             _tourStorage.GetElement(model)
         });
     }
     return(_tourStorage.GetFilteredList(model));
 }
Exemplo n.º 2
0
        public List <Tuple <string, int> > GetCountriesInfo(int touristID)
        {
            var listAllTravels = travelStorage.GetFilteredList(new TravelBindingModel
            {
                TouristID = touristID
            });

            var result = new List <Tuple <string, int> >();

            foreach (var travel in listAllTravels)
            {
                foreach (var travelTour in travel.TravelTours)
                {
                    var tour = tourStorage.GetElement(new TourBindingModel
                    {
                        ID = travelTour.Key
                    });

                    var record = result.Where(rec => rec.Item1.Equals(tour.Country)).Select(rec => new Tuple <string, int>(rec.Item1, rec.Item2)).ToList();

                    if (record.Count > 0)
                    {
                        result.Remove(record[0]);
                        record[0] = new Tuple <string, int>(tour.Country, record[0].Item2 + 1);
                        result.Add(record[0]);
                    }

                    else
                    {
                        result.Add(new Tuple <string, int>(tour.Country, 1));
                    }
                }
            }
            return(result.OrderByDescending(rec => rec.Item2).ToList());
        }