public ListResultModel<VenueModel> GetVenuesForPerformances(PerformanceFilterRequest filter)
 {
     return GetVenueForPerformances(null, filter);
 }
        public ListResultModel<VenueModel> GetVenueForPerformances(long? id, PerformanceFilterRequest filter)
        {
            IPerformanceDao performanceDao = DaoFactory.CreatePerformanceDao();
            ListResultModel<VenueModel> model;
            if ((model = HandleAuthentication<ListResultModel<VenueModel>>()) == null)
            {
                model = new ListResultModel<VenueModel>();
                try
                {
                    IList<Performance> entities = performanceDao.GetFilteredPerformancesForExport(id, filter.StartDate, filter.EndDate, filter.ArtistIds, filter.VenueIds, filter.ArtistGroupIds, filter.ArtistCategoryIds, filter.Countries, true, filter.Moved);
                    IDictionary<Venue, List<Performance>> mapEntities = entities.GroupBy(entity => entity.Venue).ToDictionary(entry => entry.Key, entry => entry.ToList());
                    model.Result = mapEntities.Select(entry =>
                    {
                        Venue venue = entry.Key;
                        List<Performance> performances = entry.Value;
                        VenueModel venueModel = new VenueModel
                        {
                            Id = venue.Id.Value,
                            Name = venue.Name,
                            FullAddress = (new StringBuilder(venue.Street).Append(", ").Append(venue.Zip).Append(venue.City).Append(" AT").ToString()),
                            GpsCoordinates = venue.GpsCoordinate,
                            Performances = performances.Select(item => new PerformanceModel
                            {
                                Id = item.Id.Value,
                                Version = item.Version.Value,
                                StartDate = item.StartDate.Value,
                                EndDate = item.EndDate.Value,
                                FormerStartDate = item.FormerStartDate,
                                FormerEndDate = item.FormerEndDate,
                                Artist = new ArtistModel
                                {
                                    Id = item.Artist.Id.Value,
                                    FirstName = item.Artist.Firstname,
                                    LastName = item.Artist.Lastname,
                                    CountryCode = item.Artist.CountryCode,
                                    ArtistGroup = ((item.Artist.ArtistGroupId != null) ? item.Artist.ArtistGroup.Name : null),
                                    ArtistCategory = item.Artist.ArtistCategory.Name
                                },
                                Venue = new VenueModel
                                {
                                    Id = item.Venue.Id.Value,
                                    Name = item.Venue.Name
                                },
                                FormerVenue = ((item.FormerVenueId != null) ? new VenueModel
                                {
                                    Id = item.FormerVenue.Id.Value,
                                    Name = item.FormerVenue.Name
                                } : null)
                            }).ToList()
                        };
                        venueModel.Performances.Sort((o1, o2) => o1.StartDate.CompareTo(o2.StartDate));
                        return venueModel;
                    }).ToList();
                }
                catch (Exception e)
                {
                    Console.WriteLine("GetVenueForPerformances: Error during processing. error: " + e.Message);
                    model.ErrorCode = (int)ErrorCode.UNKNOWN_ERROR;
                    model.Error = ($"Error during processing the request. exception={e.GetType().Name}");
                }
                finally
                {
                    DaoFactory.DisposeDao(performanceDao);
                }
            }

            return model;
        }
        public ListResultModel<PerformanceModel> GetPerformances(PerformanceFilterRequest filter)
        {
            IPerformanceDao performanceDao = DaoFactory.CreatePerformanceDao();
            ListResultModel<PerformanceModel> model = null;
            if ((model = HandleAuthentication<ListResultModel<PerformanceModel>>()) == null)
            {
                model = new ListResultModel<PerformanceModel>();
                try
                {
                    IList<Performance> performances = performanceDao.GetFilteredPerformancesForExport(null, filter.StartDate, filter.EndDate, filter.ArtistIds, filter.VenueIds, filter.ArtistGroupIds, filter.ArtistCategoryIds, filter.Countries, false, filter.Moved);
                    model.Result = performances.Select(item => new PerformanceModel
                    {
                        Id = item.Id.Value,
                        Version = item.Version.Value,
                        StartDate = item.StartDate.Value,
                        EndDate = item.EndDate.Value,
                        FormerStartDate = item.FormerStartDate,
                        FormerEndDate = item.FormerEndDate,
                        Artist = new ArtistModel
                        {
                            Id = item.Artist.Id.Value,
                            FirstName = item.Artist.Firstname,
                            LastName = item.Artist.Lastname,
                            CountryCode = item.Artist.CountryCode,
                            ArtistGroup = ((item.Artist.ArtistGroupId != null) ? item.Artist.ArtistGroup.Name : null),
                            ArtistCategory = item.Artist.ArtistCategory.Name
                        },
                        Venue = new VenueModel
                        {
                            Id = item.Venue.Id.Value,
                            Name = item.Venue.Name
                        },
                        FormerVenue = ((item.FormerVenueId != null) ? new VenueModel
                        {
                            Id = item.FormerVenue.Id.Value,
                            Name = item.FormerVenue.Name
                        } : null)
                    }).ToList();
                }
                catch (Exception e)
                {
                    Console.WriteLine("GetPerformances: Error during processing. error: " + e.Message);
                    model.ErrorCode = (int)ErrorCode.UNKNOWN_ERROR;
                    model.Error = ("Error during processing the request. error: " + e.Message);
                }
                finally
                {
                    DaoFactory.DisposeDao(performanceDao);
                }
            }

            return model;
        }