public async Task <IActionResult> Edit(int id, [Bind("ID,SeatsLeft,Time,MovieID,AuditoriumID")] Viewing viewing) { if (id != viewing.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(viewing); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ViewingExists(viewing.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuditoriumID"] = new SelectList(_context.Auditoriums, "ID", "ID", viewing.AuditoriumID); ViewData["MovieID"] = new SelectList(_context.Movies, "ID", "ID", viewing.MovieID); return(View(viewing)); }
//[ValidateAntiForgeryToken] public ActionResult Book(int?id, int nrOfTickets) { if (id == null) { return(NotFound()); } var bookedShowing = _context.Showings .Include(a => a.Lounge) .Include(m => m.Movie) .SingleOrDefault(m => m.ID == id); bookedShowing.SeatsLeft -= nrOfTickets; _context.Update(bookedShowing); _context.SaveChanges(); if (bookedShowing == null) { return(NotFound()); } return(RedirectToAction("Booked", new { id, nrOfTickets })); //return RedirectToAction(nameof(Booked), nameof(ShowingsController), ""+id +"/"+nrOfTickets); // /Showings/Booked#5/2 //return View(bookedShowing); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Seats")] Auditorium auditorium) { if (id != auditorium.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(auditorium); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuditoriumExists(auditorium.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(auditorium)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Rating,Price,Time")] Cinema cinema) { if (id != cinema.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cinema); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CinemaExists(cinema.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cinema)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,ShowingID,Seat,Booked")] ShowingSeat showingSeat) { if (id != showingSeat.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(showingSeat); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShowingSeatExists(showingSeat.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ShowingID"] = new SelectList(_context.Showings, "ID", "ID", showingSeat.ShowingID); return(View(showingSeat)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Image,Title,ReleaseDate,Genre,Rating,Description,Video")] Movie movie) { if (id != movie.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Length")] Movie movie) { if (id != movie.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,FilmStartTime")] FilmShow filmShow) { if (id != filmShow.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(filmShow); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilmShowExists(filmShow.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(filmShow)); }
public async Task <IActionResult> Edit(int id, [Bind("MovieID,Title,CategoryID,StudioID,FilmDirector,ReleaseDate,BoxOffice")] Movie movie) { if (id != movie.MovieID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.MovieID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryID", movie.CategoryID); ViewData["StudioID"] = new SelectList(_context.Studios, "StudioID", "StudioID", movie.StudioID); return(View(movie)); }
public async Task <IActionResult> Edit(int id, [Bind("BookTicketID,MovieID,HallID")] BookTicket bookTicket) { if (id != bookTicket.BookTicketID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookTicket); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookTicketExists(bookTicket.BookTicketID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["HallID"] = new SelectList(_context.Halls, "Id", "Id", bookTicket.HallID); ViewData["MovieID"] = new SelectList(_context.Movies, "Id", "Title", bookTicket.MovieID); return(View(bookTicket)); }
/// <inheritdoc cref="IUpdatable{TDto, TModel}.UpdateAsync(TDto, CancellationToken)"/> public async Task <TDto> UpdateAsync(TDto dto, CancellationToken token = default) { var entity = _mapper.Map <TModel>(dto); _context.Update(entity); await _context.SaveChangesAsync(token); var newEntity = await GetAsync(entity.Id); return(_mapper.Map <TDto>(newEntity)); }
// Får det inte att fungera med async och await här public IActionResult Details(int?id, int numberOfTickets) { if (id == null) { return(NotFound()); } var screening = _context.Screenings .Include(s => s.Auditorium) .SingleOrDefault(m => m.Id == id); if (ModelState.IsValid) { var totalTickets = screening.BookedTickets = screening.BookedTickets + numberOfTickets; try { if (totalTickets > screening.Auditorium.NumberOfSeats) { ModelState.AddModelError(string.Empty, "You can't buy more tickets than there are seats."); return(View(screening)); } else if (numberOfTickets > 12) { ModelState.AddModelError(string.Empty, "You can't buy more than 12 tickets per screening"); return(View(screening)); } else if (numberOfTickets < 1) { ModelState.AddModelError(string.Empty, "You must choose at least 1 ticket."); return(View(screening)); } else { _context.Update(screening); _context.SaveChanges(); } } catch (DbUpdateConcurrencyException) { if (!ScreeningExists(screening.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(BookingConfirmation), new { id })); } return(View(screening)); }
public string Put(string id, [FromBody] CinemaInfo value) { CinemaInfo cinema = cinemaContext.CinemaInfo.Where(u => u.Id.ToString().Equals(id)).First(); cinema.Name = value.Name; cinema.Adress = value.Adress; try { cinemaContext.Update(cinema); cinemaContext.SaveChanges(); return(JsonConvert.SerializeObject("Данные успешно изменены")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } }
public async Task <IActionResult> FinalizeBooking(int id, [Bind("Id,StartTime,MovieId,MovieTitle, SalonId, Salon")] Viewing receivedModel) { if (id != receivedModel.Id) { return(NotFound()); } if (ModelState.IsValid) { var salonFromDb = await _context.SalonList.Where(s => s.Id == receivedModel.SalonId).ToListAsync(); var salon = (Salon)salonFromDb[0]; if (salon.RemainingSeats <= 0) { return(View("BookTicketView", receivedModel)); } salon.RemainingSeats -= receivedModel.Salon.RemainingSeats; receivedModel.Salon = salon; try { _context.Update(salon); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(receivedModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("BookingConfirmation", receivedModel)); } return(View("BookTicketView", receivedModel)); }
public void OrderTicket(int userId, int seatId) { var showingSeat = _context.ShowingSeats .Include(s => s.Seat) .Include(s => s.Showing) .First(s => s.Id == seatId); _context.Update(showingSeat); showingSeat.Status = "Ordered"; var user = _context.Users.First(u => u.Id == userId); var order = new Order { User = user, ShowingSeat = showingSeat }; _context.Add(order); _context.SaveChanges(); }
public string Put(string id, [FromBody] FilmInfo value) { FilmInfo film = cinemaContext.FilmInfo.Where(u => u.Id.ToString().Equals(id)).First(); film.Name = value.Name; film.Year = value.Year; film.Country = value.Country; film.Duration = value.Duration; film.Genre = value.Genre; film.Description = value.Description; film.Poster = value.Poster; try { cinemaContext.Update(film); cinemaContext.SaveChanges(); return(JsonConvert.SerializeObject("Данные успешно изменены")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } }
public async Task <TEntity> UpdateAsync(Guid id, TEntity entity) { _dbSet.Attach(entity); _context.Update(entity).State = EntityState.Modified; return(entity); }