Esempio n. 1
0
        public async Task <IActionResult> UpdateShowTime([FromRoute] int id, [FromBody] ShowTimeViewModel showTime)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != showTime.ID)
            {
                return(BadRequest());
            }

            try
            {
                var updated = await _showTimesService.Update(showTime);

                return(Ok(updated));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (_showTimesService.GetById(id) == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 2
0
        public async Task <ShowTimeViewModel> Update(ShowTimeViewModel showTime)
        {
            var dbModel = ToShowTimeModel(showTime);
            var updated = _context.ShowTimes.Update(dbModel);
            await _context.SaveChangesAsync();

            return(ToShowTimeViewModel(updated.Entity));
        }
        public async Task <IActionResult> Index()
        {
            try
            {
                var model = await _context.Movies
                            .Where(x => x.IsCurrentlyShowing == true)
                            .OrderByDescending(x => x.Id)
                            .ToListAsync();

                var showings = await _context.MovieShowings.ToListAsync();

                ViewData["CinemaId"] = new SelectList(_context.Cinemas, "Id", "Name");

                List <ShowTimeViewModel> listShowTime = new List <ShowTimeViewModel>();

                foreach (var showing in showings ?? Enumerable.Empty <MovieShowings>())
                {
                    if (showing == null)
                    {
                    }
                    else
                    {
                        ShowTimeViewModel showTime = new ShowTimeViewModel()
                        {
                            title           = showing.Movie.Title,
                            start           = showing.ShowTime.ToString(),
                            end             = showing.ShowTime.Value.AddMinutes(showing.Movie.Duration).ToString(),
                            backgroundColor = showing.Movie.showColour,
                            borderColor     = showing.Movie.showColour
                        };

                        listShowTime.Add(showTime);
                    }
                }

                ViewBag.showtimejSON = JsonConvert.SerializeObject(listShowTime);

                HomePageViewModel homePageViewModel = new HomePageViewModel()
                {
                    Movies             = model,
                    ShowTimeViewModels = listShowTime
                };

                return(View(homePageViewModel));
            }
            catch (NullReferenceException ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
 private ShowTime ToShowTimeModel(ShowTimeViewModel s)
 {
     return(new ShowTime {
         ID = s.ID, ShowID = s.ShowID, StartDateUtc = s.StartDate.ToUniversalTime(), TicketsTotal = s.TicketsTotal
     });
 }