public Movie CreateMovie(Movie movie) { try { _context.Add(movie); _context.SaveChanges(); } catch (DbUpdateException) { return(null); } return(movie); }
public string Post([FromBody] Rating value) { if (!cinemaContext.Rating.Any(u => u.FilmId.Equals(value.FilmId) & u.UserId.Equals(value.UserId))) { Rating rating = new Rating(); rating.Id = Guid.NewGuid(); rating.UserId = value.UserId; rating.FilmId = value.FilmId; rating.Rating1 = value.Rating1; rating.Review = value.Review; try { cinemaContext.Add(rating); cinemaContext.SaveChanges(); return(JsonConvert.SerializeObject("Отзыв успешно оставлен")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return("No"); } }
public string Post([FromBody] UserData value) { if (!cinemaContext.UserData.Any(user => user.Login.Equals(value.Login))) { if (!cinemaContext.UserData.Any(user => user.Email.Equals(value.Email))) { Guid idUser = Guid.NewGuid(); UserData user = new UserData(); user.Login = value.Login; user.Email = value.Email; user.Password = value.Password; user.RoleId = value.RoleId; user.Id = idUser; try { cinemaContext.Add(user); cinemaContext.SaveChanges(); return(idUser.ToString()); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return("Email exists"); } } else { return("User exists"); } }
public string Post([FromBody] HallInfo value) { if (!cinemaContext.HallInfo.Any(hall => hall.Name.Equals(value.Name) & hall.CinemaId.Equals(value.CinemaId))) { HallInfo hall = new HallInfo(); hall.CinemaId = value.CinemaId; hall.Name = value.Name; hall.Places = value.Places; hall.Id = Guid.NewGuid(); try { cinemaContext.Add(hall); cinemaContext.SaveChanges(); return(JsonConvert.SerializeObject("Зал успешно добавлен")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return(JsonConvert.SerializeObject("Такой зал уже существует!")); } }
public string Post([FromBody] FilmInfo value) { if (!cinemaContext.FilmInfo.Any(film => film.Name.Equals(value.Name))) { FilmInfo film = new FilmInfo(); 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; film.Id = Guid.NewGuid(); try { cinemaContext.Add(film); cinemaContext.SaveChanges(); return(JsonConvert.SerializeObject("Фильм успешно добавлен")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return(JsonConvert.SerializeObject("Такой фильм уже добавлен!")); } }
public string Post([FromBody] BoughtTicket value) { List <string> idTickets = new List <string>(); List <int> placesId = new List <int>(); for (int i = 0; i < value.Place.Count(); i++) { placesId.Add(Convert.ToInt32(value.Place.ElementAt(i))); } string emailUser = value.EmailUser; bool status = false; StringBuilder stringBuilder = new StringBuilder(); Tickets tickets = new Tickets(); using (var transaction = cinemaContext.Database.BeginTransaction()) { try { for (int i = 0; i < placesId.Count(); i++) { if (!cinemaContext.Tickets.Any(u => u.Place.Equals(placesId.ElementAt(i)) && u.SeanceId.Equals(value.SeanceId))) //TicketId.Equals(placesId.ElementAt(i)))) { Guid id = Guid.NewGuid(); tickets.Id = id; tickets.SeanceId = value.SeanceId; tickets.UserId = value.IdUser; tickets.Place = placesId.ElementAt(i); cinemaContext.Add(tickets); cinemaContext.SaveChanges(); idTickets.Add(id.ToString()); } else { status = false; transaction.Rollback(); return("No"); } stringBuilder.Append(value.Place.ElementAt(i).ToString() + ","); } transaction.Commit(); status = true; SendEmailAsync(value.EmailUser, value.CinemaInfo, value.HallName, value.Film, value.Date, value.StartTime, value.EndTime, stringBuilder.ToString()).GetAwaiter(); } catch (Exception ex) { transaction.Rollback(); } if (status) { return("OK"); } else { return("No"); } } }
public async Task <IActionResult> Create([Bind("Id,Name,FilmStartTime")] FilmShow filmShow) { if (ModelState.IsValid) { _context.Add(filmShow); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(filmShow)); }
public async Task <IActionResult> Create([Bind("ID,Name,Length")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("ID,Seats")] Auditorium auditorium) { if (ModelState.IsValid) { _context.Add(auditorium); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(auditorium)); }
public async Task <IActionResult> Create([Bind("Id,Image,Title,ReleaseDate,Genre,Rating,Description,Video")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("ActorID,Name,BirthDate,BirthPlace")] Actor actor) { if (ModelState.IsValid) { _context.Add(actor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(actor)); }
public async Task <IActionResult> Create([Bind("Id,Name,Rating,Price,Time")] Cinema cinema) { if (ModelState.IsValid) { _context.Add(cinema); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cinema)); }
public void Register(string Email, string Password) { var newUser = new User { Email = Email, Password = Password }; _context.Add(newUser); _context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("ID,ShowingID,Seat,Booked")] ShowingSeat showingSeat) { if (ModelState.IsValid) { _context.Add(showingSeat); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ShowingID"] = new SelectList(_context.Showings, "ID", "ID", showingSeat.ShowingID); return(View(showingSeat)); }
public static string ImportMovies(CinemaContext context, string jsonString) { //trying solution without DTO without Validator, kids never try this at home StringBuilder sb = new StringBuilder(); var json = JsonConvert.DeserializeObject <Movie[]>(jsonString); foreach (var movie in json) { try { if (context.Movies.Any(m => m.Title == movie.Title)) { sb.AppendLine(ErrorMessage); continue; } else if (movie.Title == null || movie.Title.Length < 3 || movie.Title.Length > 20) { sb.AppendLine(ErrorMessage); continue; } else if ((int)movie.Genre > 9 || (int)movie.Genre < 0) { sb.AppendLine(ErrorMessage); continue; } else if (movie.Duration == null) { sb.AppendLine(ErrorMessage); continue; } else if (movie.Rating > 10 || movie.Rating < 1) { sb.AppendLine(ErrorMessage); continue; } else if (movie.Director == null || movie.Director.Length <= 3 || movie.Director.Length >= 20) { sb.AppendLine(ErrorMessage); continue; } context.Add(movie); context.SaveChanges(); sb.AppendLine($"Successfully imported {movie.Title} with genre {movie.Genre} and rating {movie.Rating.ToString("F2")}!"); } catch (Exception) { sb.AppendLine(ErrorMessage); } } return(sb.ToString().TrimEnd()); }
public async Task <IActionResult> Create([Bind("ID,StartTime,MovieID,LoungeID,SeatsLeft")] Showing showing) { if (ModelState.IsValid) { _context.Add(showing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LoungeID"] = new SelectList(_context.Lounges, "ID", "ID", showing.LoungeID); ViewData["MovieID"] = new SelectList(_context.Movies, "ID", "ID", showing.MovieID); return(View(showing)); }
public async Task <IActionResult> Create([Bind("ID,SeatsLeft,Time,MovieID,AuditoriumID")] Viewing viewing) { if (ModelState.IsValid) { _context.Add(viewing); await _context.SaveChangesAsync(); 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)); }
public async Task <IActionResult> Create([Bind("MovieID,Title,CategoryID,StudioID,FilmDirector,ReleaseDate,BoxOffice")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); 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> Create([Bind("BookTicketID,MovieID,HallID")] BookTicket bookTicket) { if (ModelState.IsValid) { _context.Add(bookTicket); await _context.SaveChangesAsync(); 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)); }
public async Task <IActionResult> Create([Bind("MovieGenre")] Category category) { try { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex*/) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists "); } return(View(category)); }
public static string ImportHallSeats(CinemaContext context, string jsonString) { ImportHallSeatsDto[] hallSeatsDtos = JsonConvert.DeserializeObject <ImportHallSeatsDto[]>(jsonString); StringBuilder result = new StringBuilder(); foreach (var hallSeatDto in hallSeatsDtos) { if (!isValid(hallSeatDto)) { result.AppendLine(ErrorMessage); continue; } var currentHallSeat = context.Halls.FirstOrDefault(x => x.Name == hallSeatDto.Name); if (currentHallSeat == null) { var hall = new Hall { Name = hallSeatDto.Name, Is4Dx = hallSeatDto.Is4Dx, Is3D = hallSeatDto.Is3D, Seats = new List <Seat>() }; for (int i = 0; i < hallSeatDto.Seats; i++) { var seat = new Seat { Hall = hall, HallId = hall.Id }; context.Add(seat); } context.Halls.Add(hall); string projectionType = GetProjectionType(hall.Is3D, hall.Is4Dx); result.AppendLine($"Successfully imported {hall.Name}({projectionType}) with {hall.Seats.Count} seats!"); } } context.SaveChanges(); return(result.ToString().Trim()); }
public static string ImportProjections(CinemaContext context, string xmlString) { XmlSerializer serializer = new XmlSerializer(typeof(ImportProjectionDto[]), new XmlRootAttribute("Projections")); var projectionsDtos = (ImportProjectionDto[])serializer.Deserialize(new StringReader(xmlString)); var result = new StringBuilder(); foreach (var projectionDto in projectionsDtos) { if (!projectionIsValid(projectionDto, context)) { result.AppendLine(ErrorMessage); continue; } var currentProjection = context.Projections .FirstOrDefault(x => x.HallId == projectionDto.HallId && x.MovieId == projectionDto.MovieId); if (currentProjection == null) { var dateInput = DateTime.ParseExact(projectionDto.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); string dateOutput = dateInput.ToString("MM/dd/yyyy"); var projection = new Projection { MovieId = projectionDto.MovieId, Movie = context.Movies.FirstOrDefault(x => x.Id == projectionDto.MovieId), HallId = projectionDto.HallId, Hall = context.Halls.FirstOrDefault(x => x.Id == projectionDto.HallId), DateTime = DateTime.ParseExact(dateOutput, "MM/dd/yyyy", CultureInfo.InvariantCulture) }; context.Add(projection); result.AppendLine($"Successfully imported projection {projection.Movie.Title} on {dateOutput}!"); } } context.SaveChanges(); return(result.ToString().Trim()); }
public void BuyTicket(int filmId, int customerId) { var film = _cinemaContext.Films.Find(filmId); var customer = _cinemaContext.Customers.Find(customerId); if (film != null && customer != null) { var reserve = new ReservedPlaces() { CustomerId = customerId, FilmId = filmId }; _cinemaContext.Add(reserve); _cinemaContext.SaveChanges(); } else { throw new Exception("Bad parameters"); } }
public async Task <string> Post([FromBody] SeanceData value) { Seance seance = new Seance(); Guid guid = Guid.NewGuid(); DateTime startDate = DateTime.ParseExact(value.StartTime.Replace(' ', 'T'), "yyyy-MM-ddTHH:mm:ss", null); DateTime endDate = DateTime.ParseExact(value.EndTime.Replace(' ', 'T'), "yyyy-MM-ddTHH:mm:ss", null); using var db = new CinemaContext(); { if ((await db.Seance.Where(x => x.HallId == value.HallId).ToListAsync())?.All(x => startDate.CompareTo(x.StartTime) == -1 && endDate.CompareTo(x.StartTime) == -1 || startDate.CompareTo(x.EndTime) == 1) == true) //&& !db.Seance.Any(u=>u.HallId.Equals(value.HallId))) { seance.StartTime = DateTime.ParseExact(value.StartTime, "yyyy-MM-dd HH:mm:ss", null); seance.EndTime = DateTime.ParseExact(value.EndTime, "yyyy-MM-dd HH:mm:ss", null); seance.HallId = value.HallId; seance.FilmId = value.FilmId; seance.Id = guid; seance.TicketPrice = value.TicketPrice; try { cinemaContext.Add(seance); await cinemaContext.SaveChangesAsync(); return(guid.ToString()); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return("Сеанс уже существует"); } } }
public static string ImportMovies(CinemaContext context, string jsonString) { var movieDtos = JsonConvert.DeserializeObject <ImportMovieDto[]>(jsonString); StringBuilder result = new StringBuilder(); foreach (var movieDto in movieDtos) { if (!isValid(movieDto)) { result.AppendLine(ErrorMessage); continue; } var currentMovie = context.Movies.FirstOrDefault(m => m.Title == movieDto.Title); if (currentMovie == null) { var movie = new Movie { Title = movieDto.Title, Genre = (Genre)Enum.Parse(typeof(Genre), movieDto.Genre), Duration = TimeSpan.Parse(movieDto.Duration), Rating = movieDto.Rating, Director = movieDto.Director }; context.Add(movie); result.AppendLine($"Successfully imported {movie.Title} with genre {movie.Genre} and rating {movie.Rating:f2}!"); } else { result.AppendLine(ErrorMessage); } } context.SaveChanges(); return(result.ToString().Trim()); }
public string Post([FromBody] CinemaInfo value) { if (!cinemaContext.CinemaInfo.Any(cinema => cinema.Name.Equals(value.Name))) { CinemaInfo cinema = new CinemaInfo(); cinema.Name = value.Name; cinema.Adress = value.Adress; cinema.Id = Guid.NewGuid(); try { cinemaContext.Add(cinema); cinemaContext.SaveChanges(); return(JsonConvert.SerializeObject("Кинотеатр успешно добавлен")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return(JsonConvert.SerializeObject("Такой кинотеатр уже существует!")); } }
public void Add(Order newOrder) { _context.Add(newOrder); _context.SaveChanges(); }