Beispiel #1
0
        private async void ExecuteFindPeliCommandAsync()
        {
            try
            {
                EditIsEnabled = false;

                FindEntradaFilterDTO filters = new FindEntradaFilterDTO
                {
                    NumberOfFreeSeats = NumeroDePersonas,
                    FilmId            = (Peliculas.FirstOrDefault(p => p.IsSelectedItem) ?? new FilmDTO()).Id,
                    Start             = (FechaStart ?? DateTimeOffset.Now).DateTime,
                    CinemaId          = (Cinemas.FirstOrDefault(p => p.IsSelectedItem) ?? new CinemaDTO()).Id,
                    SessionsType      = SessionTypes.Where(p => p.IsSelectedItem).Select(f => f.SessionType).ToList()
                };
                List <FindEntradaResultDTO> entradas = await _findEntradaSrv.FindEntradas((filters.Start ?? DateTime.Now)
                                                                                          , filters.SessionsType.ToArray(), filters.CinemaId, filters.FilmId);

                if (entradas != null && entradas.Any())
                {
                    List <FindEntradaResultModel> entradasModel = new List <FindEntradaResultModel>();
                    var query =
                        from entrada in entradas
                        join cine in Cinemas on entrada.CinemaId equals cine.Id
                        join peli in Peliculas on entrada.FilmId equals peli.Id
                        select new { Entrada = entrada, Cine = cine, Peli = peli };
                    foreach (var ele in query)
                    {
                        entradasModel.Add(new FindEntradaResultModel
                        {
                            SessionsId        = ele.Entrada.SessionsId,
                            FilmId            = ele.Entrada.FilmId,
                            Start             = ele.Entrada.Start,
                            IsPublished       = ele.Entrada.IsPublished,
                            ScreensId         = ele.Entrada.ScreensId,
                            ScreenName        = ele.Entrada.ScreenName,
                            CinemaId          = ele.Entrada.CinemaId,
                            NumberOfFreeSeats = ele.Entrada.NumberOfFreeSeats,
                            FilmName          = (ele.Peli ?? new FilmDTO()).Title,
                            CinemaName        = (ele.Cine ?? new CinemaDTO()).Name
                        });
                    }

                    _navigationService.NavigateTo("CinematicResultPage", filters);

                    Messenger.Default.Send(entradasModel);
                }
                else
                {
                    var dialog = new MessageDialog("Lo sentimos, no hay entradas disponibles.");
                    await dialog.ShowAsync();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                EditIsEnabled = true;
            }
        }