Пример #1
0
 public void Add(Notification notification)
 {
     using (var context = new CinemaContext())
     {
         context.Notifications.Add(notification);
         context.SaveChanges();
     }
 }
Пример #2
0
 public void Add(AuditLog auditLog)
 {
     using (var context = new CinemaContext())
     {
         context.AuditLogs.Add(auditLog);
         context.SaveChanges();
     }
 }
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            StringBuilder stBuilder = new StringBuilder();

            var xmlSeserializer = new XmlSerializer(typeof(ImportProjectionDto[]),
                                                    new XmlRootAttribute("Projections"));

            var projectionsDto = (ImportProjectionDto[])xmlSeserializer.Deserialize(new StringReader(xmlString));

            List <Projection> projectionsList = new List <Projection>();

            foreach (var projectionDto in projectionsDto)
            {
                if (!IsValid(projectionDto))
                {
                    stBuilder.AppendLine(ErrorMessage);
                    continue;
                }

                var movie      = context.Movies.Where(x => x.Id == projectionDto.MovieId).FirstOrDefault();
                var hall       = context.Halls.Where(x => x.Id == projectionDto.HallId).FirstOrDefault();
                var dateResult = new DateTime();  //2019-04-27 13:33:20 format

                var datechecker = DateTime.TryParseExact(projectionDto.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateResult);
                if (!datechecker || movie == null || hall == null)
                {
                    stBuilder.AppendLine(ErrorMessage);
                    continue;
                }

                var projection = new Projection
                {
                    MovieId  = projectionDto.MovieId,
                    Movie    = movie,
                    HallId   = projectionDto.HallId,
                    Hall     = hall,
                    DateTime = dateResult
                };

                var stringDate = dateResult.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
                projectionsList.Add(projection);
                //"Successfully imported projection {0} on {1}!";
                stBuilder.AppendLine(string.Format(SuccessfulImportProjection, movie.Title, stringDate));
            }

            context.Projections.AddRange(projectionsList);
            context.SaveChanges();

            string resultBuilder = stBuilder.ToString().TrimEnd();

            return(resultBuilder);
        }
Пример #4
0
        public static string ImportHallSeats(CinemaContext context, string jsonString)
        {
            var hallSeatDtos = JsonConvert.DeserializeObject <ImportHallSeatDto[]>(jsonString);
            var halls        = new List <Hall>();

            var sb = new StringBuilder();

            foreach (var hallSeatDto in hallSeatDtos)
            {
                if (!IsValid(hallSeatDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var hall = new Hall
                {
                    Name  = hallSeatDto.Name,
                    Is3D  = hallSeatDto.Is3D,
                    Is4Dx = hallSeatDto.Is4Dx,
                };

                for (int i = 0; i < hallSeatDto.Seats; i++)
                {
                    hall.Seats.Add(new Seat());
                }

                halls.Add(hall);

                string status = "";

                if (hall.Is4Dx)
                {
                    status = hall.Is3D ? "4Dx/3D" : "4Dx";
                }
                else if (hall.Is3D)
                {
                    status = "3D";
                }
                else
                {
                    status = "Normal";
                }

                sb.AppendLine(string.Format(SuccessfulImportHallSeat, hall.Name, status, hall.Seats.Count));
            }

            context.Halls.AddRange(halls);
            context.SaveChanges();

            return(sb.ToString());
        }
        // 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));
        }
Пример #6
0
        public static string ImportMovies(CinemaContext context, string jsonString)
        {
            var resultMessages = new List <string>();

            var movies       = JsonConvert.DeserializeObject <ImportMoviesDto[]>(jsonString);
            var resultMovies = new List <Movie>();

            foreach (var movieDto in movies)
            {
                if (movieDto.Title == null || movieDto.Title.Length < 3 || movieDto.Title.Length > 20 ||
                    movieDto.Genre == null ||
                    movieDto.Duration == null ||
                    movieDto.Rating == null || movieDto.Rating < 1 || movieDto.Rating > 10 ||
                    movieDto.Director == null || movieDto.Director.Length < 3 || movieDto.Director.Length > 20)
                {
                    resultMessages.Add(ErrorMessage);
                    continue;
                }

                //todo check
                if (!IsValid(movieDto))
                {
                    resultMessages.Add(ErrorMessage);
                    continue;
                }

                bool alreadyExists = resultMovies.Any(m => m.Title == movieDto.Title);

                if (alreadyExists == true)
                {
                    resultMessages.Add(ErrorMessage);
                    continue;
                }

                Movie movie = new Movie()
                {
                    Title    = movieDto.Title,
                    Genre    = Enum.Parse <Genre>(movieDto.Genre),
                    Duration = TimeSpan.Parse(movieDto.Duration),
                    Rating   = movieDto.Rating,
                    Director = movieDto.Director
                };

                resultMovies.Add(movie);
                resultMessages.Add(string.Format(SuccessfulImportMovie, movieDto.Title, movieDto.Genre, $"{movieDto.Rating:f2}"));
            }

            context.Movies.AddRange(resultMovies);
            context.SaveChanges();

            return(string.Join(Environment.NewLine, resultMessages));
        }
        public static string ImportCustomerTickets(CinemaContext context, string xmlString)
        {
            var xmlSerializer = new XmlSerializer(typeof(CustomerTicketsDto[]),
                                                  new XmlRootAttribute("Customers"));

            var customers = (CustomerTicketsDto[])xmlSerializer.Deserialize(new StringReader(xmlString));

            var sb = new StringBuilder();

            var validCustomer = new List <Customer>();

            foreach (var customer in customers)
            {
                var projections         = context.Projections.Select(x => x.Id).ToArray();
                var existingProjections = projections.Any(x => customer.Tickets.Any(t => t.ProjectionId != x));


                if (!IsValid(customer) && customer.Tickets.All(IsValid) && existingProjections)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var customerToAdd = new Customer
                {
                    FirstName = customer.FirstName,
                    LastName  = customer.LastName,
                    Age       = customer.Age,
                    Balance   = customer.Balance,
                };

                foreach (var ticket in customer.Tickets)
                {
                    customerToAdd.Tickets.Add(new Ticket
                    {
                        ProjectionId = ticket.ProjectionId,
                        Price        = ticket.Price
                    });
                }

                validCustomer.Add(customerToAdd);

                sb.AppendLine(string.Format(SuccessfulImportCustomerTicket, customer.FirstName, customer.LastName, customerToAdd.Tickets.Count));
            }

            context.Customers.AddRange(validCustomer);
            context.SaveChanges();



            return(sb.ToString().TrimEnd());
        }
Пример #8
0
        public static string ImportHallSeats(CinemaContext context, string jsonString)
        {
            var hallDtos = JsonConvert.DeserializeObject <ImportHallDto[]>(jsonString);

            var sb    = new StringBuilder();
            var halls = new List <Hall>();

            foreach (var dto in hallDtos)
            {
                if (!IsValid(dto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var hall = new Hall
                {
                    Name  = dto.Name,
                    Is4Dx = dto.Is4Dx,
                    Is3D  = dto.Is3D,
                };

                for (int i = 0; i < dto.Seats; i++)
                {
                    var seat = new Seat
                    {
                        HallId = hall.Id
                    };

                    hall.Seats.Add(seat);
                }

                var projectionType = hall.Is3D ? "3D" : "4Dx";
                if (hall.Is3D && hall.Is4Dx)
                {
                    projectionType = "4Dx/3";
                }
                else if (hall.Is3D == false && hall.Is4Dx == false)
                {
                    projectionType = "Normal";
                }

                halls.Add(hall);

                sb.AppendLine(string.Format(SuccessfulImportHallSeat, hall.Name, projectionType, dto.Seats));
            }

            context.Halls.AddRange(halls);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #9
0
        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());
        }
Пример #10
0
        public static string ImportHallSeats(CinemaContext context, string jsonString)
        {
            StringBuilder sb        = new StringBuilder();
            var           moviesDto = JsonConvert.DeserializeObject <List <ImportHallSeatDto> >(jsonString);
            List <Hall>   halls     = new List <Hall>();

            foreach (var hallDto in halls)
            {
                if (IsValid(hallDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var hall = new Hall
                {
                    Name  = hallDto.Name,
                    Is4Dx = hallDto.Is4Dx,
                    Is3D  = hallDto.Is3D
                };

                foreach (var seat in hallDto.Seats)
                {
                    hall.Seats.Add(new Seat());
                }

                string hallType = "";

                if (hall.Is4Dx)
                {
                    hallType = hall.Is3D ? "4Dx/3D" : "4Dx";
                }
                else if (hall.Is3D)
                {
                    hallType = "3D";
                }
                else
                {
                    hallType = "Normal";
                }

                halls.Add(hall);

                sb.AppendLine(String.Format(SuccessfulImportHallSeat, hall.Name, hallType, hall.Seats.Count));
            }

            context.Halls.AddRange(halls);
            context.SaveChanges();


            return(sb.ToString().TrimEnd());
        }
Пример #11
0
        public static string ImportHallSeats(CinemaContext context, string jsonString)
        {
            var hallsDtos = JsonConvert.DeserializeObject <ImportHallsDto[]>(jsonString);

            StringBuilder sb = new StringBuilder();

            var halls = new List <Hall>();

            foreach (var hallDto in hallsDtos)
            {
                var hall = Mapper.Map <Hall>(hallDto);

                if (!IsValid(hall) || !IsValid(hallDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                for (int i = 0; i < hallDto.SeatsCount; i++)
                {
                    hall.Seats.Add(new Seat());
                }

                string projectionType = string.Empty;

                if (hall.Is3D && hall.Is4Dx)
                {
                    projectionType = "4Dx/3D";
                }
                else if (hall.Is3D)
                {
                    projectionType = "3D";
                }
                else if (hall.Is4Dx)
                {
                    projectionType = "4Dx";
                }
                else
                {
                    projectionType = "Normal";
                }

                sb.AppendLine(String.Format(SuccessfulImportHallSeat, hall.Name, projectionType, hall.Seats.Count));

                halls.Add(hall);
            }

            context.Halls.AddRange(halls);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            var attr       = new XmlRootAttribute("Projections");
            var serializer = new XmlSerializer(typeof(List <ProjectionDto>), attr);

            var validMoviesIds = context
                                 .Movies
                                 .Select(m => m.Id)
                                 .ToList();

            var validHallIds = context
                               .Halls
                               .Select(h => h.Id)
                               .ToList();

            StringBuilder sb = new StringBuilder();
            var           validProjections = new List <Projection>();

            using (StringReader reader = new StringReader(xmlString))
            {
                var projectionsDto = (List <ProjectionDto>)serializer.Deserialize(reader);

                foreach (var dto in projectionsDto)
                {
                    if (!IsValid(dto) ||
                        !validMoviesIds.Contains(dto.MovieId) ||
                        !validHallIds.Contains(dto.HallId))
                    {
                        sb.AppendLine(ErrorMessage);
                        continue;
                    }

                    var projection = new Projection
                    {
                        MovieId  = dto.MovieId,
                        HallId   = dto.HallId,
                        DateTime = DateTime.ParseExact(dto.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
                    };

                    var movie = context.Movies.Find(projection.MovieId);

                    sb.AppendLine(string.Format(SuccessfulImportProjection, movie.Title, projection.DateTime.ToString("MM/dd/yyyy")));

                    validProjections.Add(projection);
                }
            }

            context.Projections.AddRange(validProjections);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #13
0
        public static string ImportCustomerTickets(CinemaContext context, string xmlString)
        {
            var xmlSerializer = new XmlSerializer(typeof(ImportCustomerTicketsDto[]),
                                                  new XmlRootAttribute("Customers"));

            var reader       = new StringReader(xmlString);
            var customerDtos = (ImportCustomerTicketsDto[])xmlSerializer.Deserialize(reader);
            var resultSb     = new StringBuilder();

            foreach (var customerDto in customerDtos)
            {
                if (!IsValid(customerDto))
                {
                    resultSb.AppendLine(ErrorMessage);
                    continue;
                }

                var customerTickets = new List <Ticket>();

                foreach (var ticketDto in customerDto.Tickets)
                {
                    var ticket = new Ticket()
                    {
                        ProjectionId = ticketDto.ProjectionId,
                        Price        = ticketDto.Price
                    };

                    customerTickets.Add(ticket);
                }

                var customer = new Customer()
                {
                    FirstName = customerDto.FirstName,
                    LastName  = customerDto.LastName,
                    Age       = customerDto.Age,
                    Balance   = customerDto.Balance,
                    Tickets   = customerTickets
                };

                context.Customers.Add(customer);
                context.SaveChanges();

                resultSb.AppendLine(String.Format(SuccessfulImportCustomerTicket,
                                                  customerDto.FirstName,
                                                  customerDto.LastName,
                                                  customerDto.Tickets.Count()));
            }

            var result = resultSb.ToString().TrimEnd();

            return(result);
        }
Пример #14
0
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            var sb          = new StringBuilder();
            var projections = new List <Projection>();

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ImportProjectionsDto[]), new XmlRootAttribute("Projections"));

            using (StringReader stringReader = new StringReader(xmlString))
            {
                var projectionDtos = (ImportProjectionsDto[])xmlSerializer.Deserialize(stringReader);


                foreach (var dto in projectionDtos)
                {
                    if (!IsValid(dto))
                    {
                        sb.AppendLine(ErrorMessage);
                        continue;
                    }

                    var movie = context.Movies.Find(dto.MovieId);
                    var hall  = context.Halls.Find(dto.HallId);

                    if (movie == null || hall == null)
                    {
                        sb.AppendLine(ErrorMessage);
                        continue;
                    }

                    DateTime datetime;
                    bool     isDateValid = DateTime.TryParseExact(dto.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out datetime);
                    if (!isDateValid)
                    {
                        sb.AppendLine(ErrorMessage);
                        continue;
                    }

                    var projection = new Projection
                    {
                        MovieId  = dto.MovieId,
                        HallId   = dto.HallId,
                        DateTime = datetime
                    };
                    var date = projection.DateTime.ToString("MM\\/dd\\/yyyy");
                    projections.Add(projection);
                    sb.AppendLine(string.Format(SuccessfulImportProjection, movie.Title, date));
                }
                context.Projections.AddRange(projections);
                context.SaveChanges();
            }
            return(sb.ToString().TrimEnd());
        }
Пример #15
0
        public static string ImportHallSeats(CinemaContext context, string jsonString)
        {
            StringBuilder sb    = new StringBuilder();
            var           halls = JsonConvert.DeserializeObject <IEnumerable <HallJsonInputModel> >(jsonString);

            foreach (var currnetHall in halls)
            {
                if (!IsValid(currnetHall))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var hallToAdd = new Hall
                {
                    Name  = currnetHall.Name,
                    Is4Dx = currnetHall.Is4Dx,
                    Is3D  = currnetHall.Is3D,
                };

                for (int i = 0; i < currnetHall.Seats; i++)
                {
                    hallToAdd.Seats.Add(new Seat {
                        Hall = hallToAdd
                    });
                }

                string projectionType;
                if (hallToAdd.Is4Dx && hallToAdd.Is3D)
                {
                    projectionType = "4Dx/3D";
                }
                else if (hallToAdd.Is3D && !hallToAdd.Is4Dx)
                {
                    projectionType = "3D";
                }
                else if (hallToAdd.Is4Dx && !hallToAdd.Is3D)
                {
                    projectionType = "4Dx";
                }
                else
                {
                    projectionType = "Normal";
                }

                context.Halls.Add(hallToAdd);
                context.SaveChanges();
                sb.AppendLine(string.Format(SuccessfulImportHallSeat, hallToAdd.Name, projectionType, hallToAdd.Seats.Count));
            }

            return(sb.ToString().Trim());
        }
        public static string ImportMovies(CinemaContext context, string jsonString)
        {
            var moviesDTOs = JsonConvert.DeserializeObject <ImportMoviesDto[]>(jsonString);

            var sb = new StringBuilder();

            var movies = new List <Movie>();

            foreach (var movieDto in moviesDTOs)
            {
                if (!IsValid(movieDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var isValidEnum = Enum.TryParse(movieDto.Genre, out Genre genre);

                if (!isValidEnum)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var allTitles = context.Movies
                                .Select(m => m.Title)
                                .ToHashSet();

                if (allTitles.Contains(movieDto.Title))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var movie = new Movie
                {
                    Title    = movieDto.Title,
                    Genre    = genre,
                    Duration = TimeSpan.ParseExact(movieDto.Duration, "c", null),
                    Rating   = movieDto.Rating,
                    Director = movieDto.Director
                };

                movies.Add(movie);
                sb.AppendLine(String.Format(SuccessfulImportMovie, movie.Title, movieDto.Genre, movie.Rating.ToString("f2")));
            }

            context.Movies.AddRange(movies);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #17
0
        public void Execute(int request)
        {
            var movie = _context.Movies.Find(request);

            if (movie == null) {
                throw new EntityNotFoundException(request, typeof(Movie));
            
            }

            _context.Movies.Remove(movie);
            _context.SaveChanges();

        }
Пример #18
0
        public static void Seed(CinemaContext context)
        {
            context.Users.Add(new User { Id = 1, Name = "User1" });
            context.Users.Add(new User { Id = 2, Name = "User2" });
            context.Users.Add(new User { Id = 3, Name = "User3" });
            context.Users.Add(new User { Id = 4, Name = "User4" });
            context.Users.Add(new User { Id = 5, Name = "User5" });
            context.Users.Add(new User { Id = 6, Name = "User6" });
            context.Users.Add(new User { Id = 7, Name = "User7" });
            context.Users.Add(new User { Id = 8, Name = "User8" });

            context.SaveChanges();
        }
Пример #19
0
        public static void Customer(string mail, string firstName, string lastName)
        {
            using var context = new CinemaContext();
            Customer customer = new Customer
            {
                Mail      = mail,
                FirstName = firstName,
                LastName  = lastName
            };

            context.Customer.Add(customer);
            context.SaveChanges();
        }
Пример #20
0
        public static void Seed(CinemaContext context)
        {
            context.Rooms.Add(new Room { Id = 1, RoomNumber = 1, RowsOfSeats = 5, SeatsPerRow = 10 });
            context.Rooms.Add(new Room { Id = 2, RoomNumber = 2, RowsOfSeats = 5, SeatsPerRow = 10 });
            context.Rooms.Add(new Room { Id = 3, RoomNumber = 3, RowsOfSeats = 6, SeatsPerRow = 10 });
            context.Rooms.Add(new Room { Id = 4, RoomNumber = 4, RowsOfSeats = 6, SeatsPerRow = 8 });
            context.Rooms.Add(new Room { Id = 5, RoomNumber = 5, RowsOfSeats = 6, SeatsPerRow = 8 });
            context.Rooms.Add(new Room { Id = 6, RoomNumber = 6, RowsOfSeats = 10, SeatsPerRow = 5 });
            context.Rooms.Add(new Room { Id = 7, RoomNumber = 7, RowsOfSeats = 5, SeatsPerRow = 9 });
            context.Rooms.Add(new Room { Id = 8, RoomNumber = 8, RowsOfSeats = 5, SeatsPerRow = 9 });

            context.SaveChanges();
        }
Пример #21
0
        private static void AddSeats(CinemaContext context, int hallId, int countSeats)
        {
            var seats = new List <Seat>();

            for (int i = 0; i < countSeats; i++)
            {
                seats.Add(new Seat {
                    HallId = hallId
                });
            }
            context.AddRange(seats);
            context.SaveChanges();
        }
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            var xmlSerializer = new XmlSerializer(typeof(List <ImportProjectionDto>),
                                                  new XmlRootAttribute("Projections"));

            var sb          = new StringBuilder();
            var projections = new List <Projection>();
            var hallIds     = context.Halls.Select(h => h.Id).ToList();
            var movieIds    = context.Movies.Select(m => m.Id).ToList();

            using (var reader = new StringReader(xmlString))
            {
                var projectionsFromDto = (List <ImportProjectionDto>)xmlSerializer.Deserialize(reader);

                foreach (var dto in projectionsFromDto)
                {
                    if (IsValid(dto))
                    {
                        if (hallIds.Any(x => x == dto.HallId) &&
                            movieIds.Any(x => x == dto.MovieId))
                        {
                            var currentHall  = context.Halls.FirstOrDefault(x => x.Id == dto.HallId);
                            var currentMovie = context.Movies.FirstOrDefault(x => x.Id == dto.MovieId);

                            var projection = new Projection
                            {
                                HallId   = dto.HallId,
                                Hall     = currentHall,
                                MovieId  = dto.MovieId,
                                Movie    = currentMovie,
                                DateTime = DateTime.Parse(dto.DateTime)
                            };

                            projections.Add(projection);
                            sb.AppendLine($"Successfully imported projection {projection.Movie.Title} on {projection.DateTime.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)}!");
                        }
                        else
                        {
                            sb.AppendLine(ErrorMessage);
                        }
                    }
                }

                context.Projections.AddRange(projections);
                context.SaveChanges();

                return(sb.ToString().TrimEnd());
            }

            throw new NotImplementedException();
        }
Пример #23
0
        public static void Seed(CinemaContext context)
        {
            var movies = context.Movies.ToArray();
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = movies[1].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(11, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = movies[1].MovieId, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = movies[1].MovieId, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(17, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = movies[1].MovieId, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = movies[1].MovieId, StartTime = new TimeSpan(23, 30, 0), EndTime = new TimeSpan(1, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = movies[2].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(12, 0, 0) });
            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = movies[2].MovieId, StartTime = new TimeSpan(12, 30, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = movies[2].MovieId, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(18, 0, 0) });
            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = movies[2].MovieId, StartTime = new TimeSpan(21, 00, 0), EndTime = new TimeSpan(23, 00, 0) });

            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = movies[3].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(12, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = movies[3].MovieId, StartTime = new TimeSpan(13, 0, 0), EndTime = new TimeSpan(16, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = movies[3].MovieId, StartTime = new TimeSpan(17, 0, 0), EndTime = new TimeSpan(20, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = movies[4].MovieId, StartTime = new TimeSpan(10, 0, 0), EndTime = new TimeSpan(12, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = movies[4].MovieId, StartTime = new TimeSpan(13, 0, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = movies[4].MovieId, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(18, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = movies[4].MovieId, StartTime = new TimeSpan(20, 0, 0), EndTime = new TimeSpan(21, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = movies[5].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(10, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = movies[5].MovieId, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(13, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = movies[5].MovieId, StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(15, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = movies[5].MovieId, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(16, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = movies[5].MovieId, StartTime = new TimeSpan(18, 0, 0), EndTime = new TimeSpan(18, 40, 0) });

            context.Seanses.Add(new Seanse { RoomId = 6, MovieId = movies[6].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(12, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 6, MovieId = movies[6].MovieId, StartTime = new TimeSpan(13, 0, 0), EndTime = new TimeSpan(16, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 6, MovieId = movies[6].MovieId, StartTime = new TimeSpan(17, 0, 0), EndTime = new TimeSpan(20, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = movies[7].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(11, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = movies[7].MovieId, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = movies[7].MovieId, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(17, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = movies[7].MovieId, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = movies[8].MovieId, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(11, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = movies[8].MovieId, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(15, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = movies[8].MovieId, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(17, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = movies[8].MovieId, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 40, 0) });

            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = movies[9].MovieId, StartTime = new TimeSpan(18, 0, 0), EndTime = new TimeSpan(20, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = movies[9].MovieId, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = movies[0].MovieId, StartTime = new TimeSpan(22, 0, 0), EndTime = new TimeSpan(23, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = movies[0].MovieId, StartTime = new TimeSpan(18, 20, 0), EndTime = new TimeSpan(22, 00, 0) });

            context.SaveChanges();
        }
Пример #24
0
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            var projectionsDtos = XmlConverter.Deserializer <ImportProjectionsDTO>(xmlString, "Projections");
            var projectionsList = new List <Projection>();
            var sb = new StringBuilder();

            foreach (var pDto in projectionsDtos)
            {
                if (!IsValid(pDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var validHall  = context.Halls.FirstOrDefault(x => x.Id == pDto.HallId);
                var validMovie = context.Movies.FirstOrDefault(x => x.Id == pDto.MovieId);

                if (validHall == null || validMovie == null)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                DateTime dateTime;
                var      isDateTimeValid = DateTime.TryParseExact
                                               (pDto.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime);

                if (!isDateTimeValid)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var projection = new Projection
                {
                    MovieId  = pDto.MovieId,
                    Hall     = validHall,
                    Movie    = validMovie,
                    DateTime = dateTime,
                };

                projectionsList.Add(projection);
                sb.AppendLine(
                    string.Format(SuccessfulImportProjection, validMovie.Title, dateTime.ToString("MM/dd/yyyy")));
            }

            context.Projections.AddRange(projectionsList);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #25
0
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            StringBuilder sb = new StringBuilder();

            var serializer = new XmlSerializer(typeof(ImportProjectionDto[]),
                                               new XmlRootAttribute("Projections"));

            var projectionsDto = (ImportProjectionDto[])serializer.Deserialize(new StringReader(xmlString));


            foreach (var projectionDto in projectionsDto)
            {
                if (!IsValid(projectionDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                Movie movie = context.Movies.FirstOrDefault(x => x.Id == projectionDto.MovieId);

                if (movie == null)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                Hall hall = context.Halls.FirstOrDefault(x => x.Id == projectionDto.HallId);

                if (hall == null)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                Projection projection = new Projection
                {
                    MovieId  = projectionDto.MovieId,
                    HallId   = projectionDto.HallId,
                    DateTime = DateTime.ParseExact(projectionDto.DateTime, @"yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
                };

                context.Projections.Add(projection);
                sb.AppendLine(string.Format(SuccessfulImportProjection,
                                            projection.Movie.Title,
                                            projection.DateTime.ToString(@"MM/dd/yyyy")));
            }

            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #26
0
        public static string ImportCustomerTickets(CinemaContext context, string xmlString)
        {
            var serializer = new XmlSerializer(typeof(ImportCustomersDto[]),
                                               new XmlRootAttribute("Customers"));

            ImportCustomersDto[] customersDto;
            var sb        = new StringBuilder();
            var customers = new List <Customer>();

            using (var reader = new StringReader(xmlString))
            {
                customersDto = (ImportCustomersDto[])serializer.Deserialize(reader);
            }

            foreach (var custdto in customersDto)
            {
                if (!IsValid(custdto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var customer = new Customer
                {
                    FirstName = custdto.FirstName,
                    LastName  = custdto.LastName,
                    Age       = custdto.Age,
                    Balance   = custdto.Balance,
                };

                foreach (var ticketDto in custdto.Tickets)
                {
                    var ticket = new Ticket
                    {
                        CustomerId   = customer.Id,
                        ProjectionId = ticketDto.ProjectionId,
                        Price        = ticketDto.Price
                    };

                    customer.Tickets.Add(ticket);
                    customers.Add(customer);
                }

                sb.AppendLine(string.Format(SuccessfulImportCustomerTicket, customer.FirstName, customer.LastName, customer.Tickets.Count));
            }

            context.Customers.AddRange(customers);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #27
0
        // XML
        public static string ImportCustomerTickets(CinemaContext context, string xmlString)
        {
            var serializer   = new XmlSerializer(typeof(List <ImportTicketDto>), new XmlRootAttribute("Customers"));
            var custmersDTOs = (List <ImportTicketDto>)serializer.Deserialize(new StringReader(xmlString));

            var customers = new List <Customer>();
            var tickets   = new List <Ticket>();

            var sb = new StringBuilder();

            foreach (var dto in custmersDTOs)
            {
                var isValid = IsValid(dto);

                if (!isValid)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var customer = new Customer()
                {
                    FirstName = dto.FirstName,
                    LastName  = dto.LastName,
                    Age       = dto.Age,
                    Balance   = dto.Balance
                };

                foreach (var ticketDTO in dto.Tickets)
                {
                    var ticket = new Ticket()
                    {
                        ProjectionId = ticketDTO.ProjectionId,
                        Price        = ticketDTO.Price
                    };

                    customer.Tickets.Add(ticket);
                    tickets.Add(ticket);
                }

                var result = String.Format(SuccessfulImportCustomerTicket, customer.FirstName, customer.LastName, customer.Tickets.Count);
                sb.AppendLine(result);
                customers.Add(customer);
            }

            context.Customers.AddRange(customers);
            context.Tickets.AddRange(tickets);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            var serializer     = new XmlSerializer(typeof(ImportProjectionDto[]), new XmlRootAttribute("Projections"));
            var projectionsDto = (ImportProjectionDto[])serializer.Deserialize(new StringReader(xmlString));
            var sb             = new StringBuilder();

            var projections = new List <Projection>();

            foreach (var projDto in projectionsDto)
            {
                var movie = context.Movies.FirstOrDefault(m => m.Id == projDto.MovieId);
                var hall  = context.Halls.FirstOrDefault(m => m.Id == projDto.HallId);

                if (!IsValid(projDto) || movie == null || hall == null)
                {
                    sb.AppendLine("Invalid data!");
                    continue;
                }

                DateTime date;

                bool isDateParsed =
                    DateTime.TryParseExact(projDto.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);

                if (!isDateParsed)
                {
                    sb.AppendLine("Invalid data!");
                    continue;
                }

                string dateAsStr = date.ToString("MM/dd/yyyy");

                var projection = new Projection
                {
                    MovieId  = projDto.MovieId,
                    HallId   = projDto.HallId,
                    DateTime = DateTime.ParseExact(dateAsStr, "MM/dd/yyyy", CultureInfo.InvariantCulture)
                };

                projections.Add(projection);

                //Projection moviePorj = context.Projections.FirstOrDefault(p => p.MovieId == projection.MovieId);
                // var movieTitle = moviePorj.Movie.Title;

                sb.AppendLine($"Successfully imported projection {movie.Title} on {projection.DateTime.ToString("MM/dd/yyyy")}!");
            }

            context.Projections.AddRange(projections);
            context.SaveChanges();
            return(sb.ToString().TrimEnd());
        }
Пример #29
0
        public static void Booking(int customerId, int movieId, int quantity)
        {
            using CinemaContext context = new CinemaContext();
            Booking booking = new Booking
            {
                CustomerId    = customerId,
                MovieId       = movieId,
                BookingNumber = GetBookingNumber(),
                Quantity      = quantity
            };

            context.Booking.Add(booking);
            context.SaveChanges();
        }
        public void Execute(ReservationDTO request)
        {
            validator.ValidateAndThrow(request);

            _context.Reservation.Add(new Domain.Reservation
            {
                MovieName = request.MovieName
            });
            _context.Tickets.Add(new Domain.Tickets
            {
                TicketPrice = request.Ticket
            });
            _context.SaveChanges();
        }
Пример #31
0
        public static void Seed(CinemaContext context)
        {
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = 1, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(11, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = 1, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = 1, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(17, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = 1, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = 1, StartTime = new TimeSpan(23, 30, 0), EndTime = new TimeSpan(1, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = 2, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(12, 0, 0) });
            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = 2, StartTime = new TimeSpan(12, 30, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = 2, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(18, 0, 0) });
            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = 2, StartTime = new TimeSpan(21, 00, 0), EndTime = new TimeSpan(23, 00, 0) });

            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = 3, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(12, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = 3, StartTime = new TimeSpan(13, 0, 0), EndTime = new TimeSpan(16, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = 3, StartTime = new TimeSpan(17, 0, 0), EndTime = new TimeSpan(20, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = 4, StartTime = new TimeSpan(10, 0, 0), EndTime = new TimeSpan(12, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = 4, StartTime = new TimeSpan(13, 0, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = 4, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(18, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 4, MovieId = 4, StartTime = new TimeSpan(20, 0, 0), EndTime = new TimeSpan(21, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = 5, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(10, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = 5, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(13, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = 5, StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(15, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = 5, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(16, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 5, MovieId = 5, StartTime = new TimeSpan(18, 0, 0), EndTime = new TimeSpan(18, 40, 0) });

            context.Seanses.Add(new Seanse { RoomId = 6, MovieId = 6, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(12, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 6, MovieId = 6, StartTime = new TimeSpan(13, 0, 0), EndTime = new TimeSpan(16, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 6, MovieId = 6, StartTime = new TimeSpan(17, 0, 0), EndTime = new TimeSpan(20, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = 7, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(11, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = 7, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(15, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = 7, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(17, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 7, MovieId = 7, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = 8, StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(11, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = 8, StartTime = new TimeSpan(12, 0, 0), EndTime = new TimeSpan(15, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = 8, StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(17, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 8, MovieId = 8, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 40, 0) });

            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = 9, StartTime = new TimeSpan(18, 0, 0), EndTime = new TimeSpan(20, 30, 0) });
            context.Seanses.Add(new Seanse { RoomId = 3, MovieId = 9, StartTime = new TimeSpan(21, 0, 0), EndTime = new TimeSpan(23, 30, 0) });

            context.Seanses.Add(new Seanse { RoomId = 2, MovieId = 10, StartTime = new TimeSpan(22, 0, 0), EndTime = new TimeSpan(23, 40, 0) });
            context.Seanses.Add(new Seanse { RoomId = 1, MovieId = 10, StartTime = new TimeSpan(18, 20, 0), EndTime = new TimeSpan(22, 00, 0) });

            context.SaveChanges();
        }
Пример #32
0
        static void Main(string[] args)
        {
            using (var context = new CinemaContext())
            {
                AccessLevel lvl = new AccessLevel {
                    LevelID = 10, LevelName = "My access"
                };
                context.AccessLevels.Add(lvl);
                context.SaveChanges();
            }

            Console.WriteLine("I am done!");
            Console.ReadLine();
        }
Пример #33
0
        public IActionResult Ban(string id)
        {
            var user = this.context.Users.Find(id);

            if (user == null)
            {
                return(NotFound());
            }

            user.LockoutEnd = DateTime.Parse("Jan 1, 2030");
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Пример #34
0
        public ActionResult UploadeImage(HttpPostedFileBase upload)
        {
            var FilmId      = Request["FilmId"];
            var RedirectUrl = Request["RedirectUrl"];

            if (upload != null && upload.ContentLength > 0)
            {
                var photo = new File
                {
                    FileName    = System.IO.Path.GetFileName(upload.FileName),
                    FileType    = FileType.Photo,
                    ContentType = upload.ContentType
                };
                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    photo.Content = reader.ReadBytes(upload.ContentLength);
                }
                photo.FilmId = int.Parse(FilmId);
                db.Files.Add(photo);
                db.SaveChanges();
            }
            return(Redirect(RedirectUrl));
        }
Пример #35
0
        public static string ImportCustomerTickets(CinemaContext context, string xmlString)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(CustomerDto[]), new XmlRootAttribute("Customers"));

            var customersDtos = (CustomerDto[])serializer.Deserialize(new StringReader(xmlString));

            var result = new StringBuilder();

            foreach (var customerDto in customersDtos)
            {
                if (!isValid(customerDto))
                {
                    result.AppendLine(ErrorMessage);
                    continue;
                }

                var currentCustomer = context.Customers
                                      .FirstOrDefault(x => x.FirstName == customerDto.FirstName && x.LastName == customerDto.LastName);

                if (currentCustomer == null)
                {
                    var customer = new Customer
                    {
                        FirstName = customerDto.FirstName,
                        LastName  = customerDto.LastName,
                        Age       = customerDto.Age,
                        Balance   = customerDto.Balance,
                        Tickets   = new List <Ticket>()
                    };

                    foreach (var ticketDto in customerDto.Tickets)
                    {
                        var ticket = new Ticket
                        {
                            Price        = ticketDto.Price,
                            CustomerId   = customer.Id,
                            Customer     = customer,
                            ProjectionId = ticketDto.ProjectionId,
                            Projection   = context.Projections.FirstOrDefault(p => p.Id == ticketDto.ProjectionId)
                        };
                        customer.Tickets.Add(ticket);
                    }

                    context.Customers.Add(customer);
                    result.AppendLine($"Successfully imported customer {customer.FirstName} {customer.LastName} with bought tickets: {customer.Tickets.Count}!");
                }
            }
            context.SaveChanges();
            return(result.ToString().Trim());
        }
Пример #36
0
        public static string ImportProjections(CinemaContext context, string xmlString)
        {
            XmlSerializer xml = new XmlSerializer(typeof(ImportProjectionDto[]), new XmlRootAttribute("Projections"));

            var projectionsDto = (ImportProjectionDto[])xml.Deserialize(new StringReader(xmlString));

            var projections = new List <Projection>();

            var sb = new StringBuilder();

            foreach (var projection in projectionsDto)
            {
                var salesToAdd = Mapper.Map <Projection>(projection);

                if (!IsValid(salesToAdd))
                {
                    sb.AppendLine(ErrorMessage);
                }
                else
                {
                    var movie = context
                                .Movies
                                .Select(m => new
                    {
                        m.Id,
                        m.Title
                    })
                                .ToList();

                    var moviesCount = context.Movies.Count();
                    var hallsCount  = context.Halls.Count();

                    if (salesToAdd.HallId < 1 || salesToAdd.HallId > hallsCount || salesToAdd.MovieId > moviesCount || salesToAdd.MovieId < 1)
                    {
                        sb.AppendLine(ErrorMessage);
                        continue;
                    }

                    string neededTitle = movie.Where(x => x.Id == salesToAdd.MovieId).First().Title;

                    sb.AppendLine(string.Format(SuccessfulImportProjection, neededTitle, salesToAdd.DateTime.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)));
                    projections.Add(salesToAdd);
                }
            }

            context.Projections.AddRange(projections);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #37
0
        public static void Seed(CinemaContext context)
        {
            var hasher = new StringHasher();
            for (int i = 1; i <= 10; i++)
            {
                context.Users.Add(new User
                {
                    Id = 1,
                    Name = "User" + i,
                    Email = i + "@movie.com",
                    ContactByEmailAllowed = true,
                    MobilePhone = "" + i + i + i + i + i,
                    ContactBySmslAllowed = true,
                    Password = hasher.GetHash("123", "user" + i),
                    PasswordSalt = "user" + i,
                    UserType = (UserType)(i % 3)
                });
            }

            context.SaveChanges();
        }
Пример #38
0
        public static void Seed(CinemaContext context)
        {
            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
                Title = "The Shawshank Redemption",
                Length = TimeSpan.FromMinutes(142)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.",
                Title = "The Godfather",
                Length = TimeSpan.FromMinutes(175)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "The early life and career of Vito Corleone in 1920s New York is portrayed while his son, Michael, expands and tightens his grip on his crime syndicate stretching from Lake Tahoe, Nevada to pre-revolution 1958 Cuba.",
                Title = "The Godfather: Part II",
                Length = TimeSpan.FromMinutes(200)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
                Title = "The Dark Knight",
                Length = TimeSpan.FromMinutes(152)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "A dissenting juror in a murder trial slowly manages to convince the others that the case is not as obviously clear as it seemed in court.",
                Title = "12 Angry Men",
                Length = TimeSpan.FromMinutes(96)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "In Poland during World War II, Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.",
                Title = "Schindler's List",
                Length = TimeSpan.FromMinutes(195)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Description = "The lives of two mob hit men, a boxer, a gangster's wife, and a pair of diner bandits intertwine in four tales of violence and redemption.",
                Title = "Pulp fiction",
                Length = TimeSpan.FromMinutes(154)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Title = "Good bad and ugly",
                Description = "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.",
                Length = TimeSpan.FromMinutes(161)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Title = "The Lord of the Rings: The Return of the King",
                Description = "Gandalf and Aragorn lead the World of Men against Sauron's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.",
                Length = TimeSpan.FromMinutes(201)
            });

            context.Movies.Add(new Movie
            {
                MovieId = Guid.NewGuid(),
                Title = "Fight Club",
                Description = "An insomniac office worker, looking for a way to change his life, crosses paths with a devil-may-care soap maker, forming an underground fight club that evolves into something much, much more...",
                Length = TimeSpan.FromMinutes(139)
            });

            context.SaveChanges();
        }