public CreateUserCommand(MFGContext context, IMapper mapper, UserCreateDtoValidator validator, IEmailSender emailSender)
 {
     _context     = context;
     _mapper      = mapper;
     _validator   = validator;
     _emailSender = emailSender;
 }
        public HallValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name field is required")
            .MinimumLength(3)
            .WithMessage("Name field must have at least 3 characters")
            .MaximumLength(30)
            .WithMessage("Name field can have maximum 30 characters");

            RuleFor(x => x.NumberOfSeats)
            .NotEmpty()
            .WithMessage("NumberOfSeats field is required")
            .InclusiveBetween(10, 90000)
            .WithMessage("NumberOfSeats must be between 10 and 90000");

            RuleFor(x => x.LocationID)
            .NotNull()
            .WithMessage("LocationID field is required")
            .Must(p => _context.Locations.Any(x => x.Id == p))
            .WithMessage("LocationID not valid!")
            .DependentRules(() =>
            {
                RuleFor(x => x.Name)
                .Must((h, n) => !_context.Halls.Any(x => x.Name.ToLower() == h.Name.ToLower() && x.LocationID == h.LocationID))
                .WithMessage("There is allready hall with that name in that location");
            });
        }
예제 #3
0
        public CityValidator(MFGContext context)
        {
            _context = context;

            /*
             *
             *
             * RuleFor(x => x.Surname).NotNull().DependentRules(() => {
             *   RuleFor(x => x.Forename).NotNull();
             *  });
             *
             * */
            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("City name is required")
            .MinimumLength(3)
            .WithMessage("City name must have at least 3 characters")
            .MaximumLength(20)
            .WithMessage("City name can have maximum 20 characters")
            .DependentRules(() =>
            {
                RuleFor(x => x.Name)
                .Must(n => !_context.Cities.Any(x => x.Name.ToLower() == n.ToLower()))
                .WithMessage("City name must be unique");
            });
        }
        public TicketCreateDtoValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.FestivalID)
            .NotNull()
            .WithMessage("FestivalID field is required")
            .Must(p => _context.Festivals.Any(x => x.Id == p))
            .WithMessage("FestivalID not valid!");

            RuleFor(x => x.ProjectionID)
            .NotNull()
            .WithMessage("ProjectionID field is required")
            .Must(p => _context.Projections.Any(x => x.Id == p))
            .WithMessage("ProjectionID not valid!");

            RuleFor(x => x.Price)
            //  .NotNull()     moze not Empty da ne dozvoli 0, ali moze da kosta 0 ako je besplatan ulaz
            // .WithMessage("Price field is required")
            .LessThan(1000000000)
            .WithMessage("Price can have maximum 10 characters");

            RuleFor(x => x)
            .Must(t => !_context.Tickets.Any(x => x.FestivalID == t.FestivalID && x.ProjectionID == t.ProjectionID))
            .WithMessage("Ticket for that festival and that projection already exists!");
        }
        public void SetInitialValuesMovie(MFGContext context)
        {
            var fakeDataMaker = new AddFakeData();

            var fakeMovies = fakeDataMaker.CreateFakeMovies(50);

            var fakeDirectors = fakeDataMaker.CreateFakeDirectors(150).ToList();

            foreach (var m in fakeMovies)
            {
                var numOfDierctors = fakeDataMaker.RandomNumber(1, 2);

                for (var i = 0; i < numOfDierctors; i++)
                {
                    var _ = fakeDataMaker.RandomNumber(0, 59);
                    m.MovieDirectors.Add(
                        new MovieDirector
                    {
                        Director = fakeDirectors[_]
                    });
                }
            }

            context.Movies.AddRange(fakeMovies);
            context.SaveChanges();
        }
        public LocationCreateDtoValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name field is required")
            .MinimumLength(3)
            .WithMessage("Name field must have at least 3 characters")
            .MaximumLength(50)
            .WithMessage("Name field can have maximum 50 characters")
            .DependentRules(() =>
            {
                /*RuleFor(x => x.Name)
                 * .Must(n => !_context.Locations.Any(x => x.Name.ToLower() == n.ToLower()))
                 * .WithMessage("Name must be unique! we are working to fix this");*/
                RuleFor(x => x)
                .Must(n => !_context.Locations.Any(x => x.Name.ToLower() == n.Name.ToLower() && x.CityID == n.CityID))
                .WithMessage("Name can be used once per city");
            });

            RuleFor(x => x.CityID)
            .NotNull()
            .WithMessage("CityID field is required")
            .Must(p => _context.Cities.Any(x => x.Id == p))
            .WithMessage("CityID not valid!");
        }
예제 #7
0
        public FestivalCreateDtoValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name is required")
            .MinimumLength(3)
            .WithMessage("Name must have at least 3 characters")
            .MaximumLength(30)
            .WithMessage("Maximu length for name is 30");

            RuleFor(x => x.MaxTickets)
            .NotEmpty()
            .WithMessage("Maximum number if tickets is required")
            .ExclusiveBetween(1, 50)
            .WithMessage("Maximum number if tickets must be between 1 and 50");

            RuleFor(x => x.StartDate)
            .NotNull()
            .WithMessage("StartDate is required")
            .GreaterThanOrEqualTo(DateTime.Now)
            .WithMessage("You can't add festivals in past!");

            RuleFor(x => x.EndDate)
            .NotNull()
            .WithMessage("EndDate is required")
            .GreaterThanOrEqualTo(DateTime.Now)
            .WithMessage("You can't add festivals that ended in the past!")
            .GreaterThan(x => x.StartDate)
            .WithMessage("End date must be after start date!");

            RuleFor(x => x.About)
            .NotNull()
            .WithMessage("About field is required")
            .MinimumLength(30)
            .WithMessage("About field must have at least 30 characters");

            RuleFor(x => x.PlaceID)
            .NotNull()
            .WithMessage("PlaceID field is required")
            .Must(p => _context.Places.Any(x => x.Id == p))
            .WithMessage("PlaceID not valid!")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(t => !_context.Festivals.Any(f => f.Name.ToLower() == t.Name.ToLower() && f.StartDate == t.StartDate && f.EndDate == t.EndDate))
                .WithMessage("Festival with that name, start and end time already exists!");
            });

            /*  RuleForEach(x => x.Projections)
             *    .Must(p => _context.Projections.Any(x => x.Id == p))
             *    .WithMessage("One of projections is invalid!");
             *
             * RuleForEach(x => x.Tickets)
             *    .Must(p => _context.Tickets.Any(x => x.Id == p))
             *    .WithMessage("One of tickets is invalid!");
             */
        }
예제 #8
0
        public PickTicketReservationValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.ReservationCode)
            .Must(x => _context.TicketReservations.Any(t => t.ReservationCode == x))
            .WithMessage("Invalid reservation code");
        }
        public void CreateFakeProjections(MFGContext context)
        {
            var festivals = context.Festivals.ToList();

            foreach (var f in festivals)
            {
                CreateFakeProjection(context, f.Id);
            }
        }
예제 #10
0
        public UserCreateDtoValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.FirstName)
            .NotEmpty()
            .WithMessage("First name is required")
            .MinimumLength(3)
            .WithMessage("First name must have at least 3 characters")
            .MaximumLength(30)
            .WithMessage("First name can have maximum 30 characters");

            RuleFor(x => x.LastName)
            .NotEmpty()
            .WithMessage("Last name name is required")
            .MinimumLength(2)
            .WithMessage("Last name must have at least 2 characters")
            .MaximumLength(40)
            .WithMessage("Last name can have maximum 40 characters");

            RuleFor(x => x.Email)
            .NotEmpty()
            .WithMessage("Email is required")
            .EmailAddress()
            .WithMessage("Email must me in email fomat...")
            .MaximumLength(50)
            .WithMessage("Email can have maximum 50 characters")
            .DependentRules(() =>
            {
                RuleFor(x => x.Email)
                .Must((e, n) => !_context.Users.Any(x => x.Email.ToLower() == n.ToLower()))
                .WithMessage("Email  must be unique");
            });

            RuleFor(x => x.Username)
            .NotEmpty()
            .WithMessage("Username is required")
            .MinimumLength(3)
            .WithMessage("Username must have at least 3 characters")
            .MaximumLength(30)
            .WithMessage("Username can have maximum 30 characters")
            .DependentRules(() =>
            {
                RuleFor(x => x.Username)
                .Must((u, n) => !_context.Users.Any(x => x.Username.ToLower() == n.ToLower()))
                .WithMessage("Username  must be unique");
            });

            RuleFor(x => x.Password)
            .NotEmpty()
            .WithMessage("Password is required")
            .MinimumLength(3)
            .WithMessage("Password must have at least 3 characters")
            .MaximumLength(30)
            .WithMessage("Password can have maximum 30 characters");
        }
        public void CreateFakeFestivals(MFGContext context)
        {
            ICollection <Festival> festivals = new HashSet <Festival>();

            for (var i = 0; i < 5; i++)
            {
                CreateFakeFestival(festivals, i);
            }
            context.Festivals.AddRange(festivals);
            context.SaveChanges();
        }
예제 #12
0
        public PlaceValidator(MFGContext context)
        {
            _context = context;

            bool cityId     = false;
            bool locationId = false;

            RuleFor(x => x.CityID)
            .NotNull()
            .WithMessage("CityID field is required")
            .DependentRules(() =>
            {
                RuleFor(x => x.CityID)
                .Must(p =>
                {
                    cityId = _context.Cities.Any(x => x.Id == p);
                    return(cityId);
                })
                .WithMessage("CityID not valid!");
            });

            RuleFor(x => x.LocationID)
            .NotNull()
            .WithMessage("LocationID field is required")
            .DependentRules(() =>
            {
                RuleFor(x => x.LocationID)
                .Must(p =>
                {
                    locationId = _context.Locations.Any(x => x.Id == p);
                    return(locationId);
                })
                .WithMessage("LocationID not valid!");

                RuleFor(x => x.LocationID)
                .Must((p, l) => !_context.Places.Any(x => x.Id != p.Id && p.LocationID == x.LocationID))
                .WithMessage("That location is already taken...  /* moguce neka smislenija poruka*/");

                RuleFor(x => x.LocationID)
                .Must((p, i) =>
                {
                    if (!(locationId && cityId))
                    {
                        return(true);
                    }
                    var tmp = !_context.Places.Any(x => x.LocationID == p.LocationID && x.CityID == p.CityID);

                    return(tmp);
                })
                .WithMessage("Place with that location and that city already exists");
            });
        }
예제 #13
0
        public BuyTicketReservationValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x)
            .Must(x => _context.TicketReservations.Any(t => t.Id == x))
            .WithMessage("Invalid Reservation ID")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(t =>
                {
                    return(_context.TicketReservations.Find(t).Bought == null);
                })
                .WithMessage("Tickets are already picked up!");
            });
        }
        public ProjectionValidator(MFGContext context)
        {
            _context = context;
            bool fest = false;

            Festival f = new Festival();

            RuleFor(x => x.HallID)
            .NotNull()
            .WithMessage("HallID field is required")
            .Must(p => _context.Halls.Any(x => x.Id == p))
            .WithMessage("HallID not valid!");

            RuleFor(x => x.FestivalID)
            .NotNull()
            .WithMessage("FestivalID field is required")
            .Must(p =>
            {
                fest = _context.Festivals.Any(x => x.Id == p);
                if (fest)
                {
                    f = _context.Festivals.FirstOrDefault(x => x.Id == p);
                }
                return(fest);
            })
            .WithMessage("FestivalID not valid!");

            RuleFor(x => x.MovieID)
            .NotNull()
            .WithMessage("MovieID field is required")
            .Must(p => _context.Movies.Any(x => x.Id == p))
            .WithMessage("MovieID not valid!");

            if (fest) //ovo mozda ne radi!!!! dobro proveri
            {
                RuleFor(x => x.BeginsAt)
                .InclusiveBetween(f.StartDate, f.EndDate)
                .WithMessage("Projection must be between festival's start and end date!");

                RuleFor(x => x.EndsAt)
                .GreaterThan(p => p.BeginsAt)
                .WithMessage("Projection must start before it ends...")
                .InclusiveBetween(f.StartDate, f.EndDate)
                .WithMessage("Projection must be between festival's start and end date!");
            }
        }
        public void CreateFakeTickets(MFGContext context)
        {
            var projections = context.Projections.ToList();

            foreach (var p in projections)
            {
                context.Tickets.Add(
                    new Ticket
                {
                    Price        = RandomNumber(150, 990),
                    FestivalID   = p.FestivalID,
                    ProjectionID = p.Id,
                    CreatedAt    = DateTime.UtcNow,
                    IsActive     = true
                }
                    );
            }
            context.SaveChanges();
        }
예제 #16
0
        public MovieValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name field is required")
            .MinimumLength(3)
            .WithMessage("Name field must have at least 3 characters")
            .MaximumLength(30)
            .WithMessage("Name field can have maximum 30 characters");

            RuleFor(x => x.Length)
            .NotEmpty()
            .WithMessage("Length field is required")
            .InclusiveBetween(10, 500)
            .WithMessage("Movie must last between 10 and 500 minutes");

            RuleFor(x => x.AvgRating)
            .NotEmpty()
            .WithMessage("AvgRating field is required")
            .InclusiveBetween(1, 5)
            .WithMessage("AvgRating must be between 1 and 5");

            RuleFor(x => x.Year)
            .NotEmpty()
            .WithMessage("Year field is required")
            .InclusiveBetween(1900, DateTime.Now.Year)
            .WithMessage("Year must be  between 1900 and current year");

            RuleFor(x => x.Directors)
            .NotEmpty()
            .WithMessage("You must select at least 1 director")
            //  .Must(x=> _context.MovieDirector.Where(x=> x.DirectorID ==))   -> DISTINCT !!!! ne moze isti reziser da rezira isti film nekoli puta
            .DependentRules(() =>
            {
                RuleForEach(x => x.Directors)
                .NotNull()
                .WithMessage("You must select at least 1 director")
                .Must(i => _context.Directors.Any(x => x.Id == i))
                .WithMessage("Director ID not valid");
            });
        }
        public LocationValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name field is required")
            .MinimumLength(3)
            .WithMessage("Name field must have at least 3 characters")
            .MaximumLength(50)
            .WithMessage("Name field can have maximum 50 characters")
            .DependentRules(() =>
            {
                RuleFor(x => x)
                .Must(n => !_context.Locations.Any(x => x.Name.ToLower() == n.Name.ToLower() && x.CityID == n.CityID))
                .WithMessage("Name can be used once per city");
            });

            RuleFor(x => x.CityID)
            .NotNull()
            .WithMessage("CityID field is required")
            .Must(p => _context.Cities.Any(x => x.Id == p))
            .WithMessage("CityID not valid!");

            /*      da li mi halls trebaju u locationu?
             * RuleForEach(x => x.Halls)
             *  .Must(p => _context.Halls.Any(x => x.Id == p.Id))
             *  .WithMessage("HallID not valid");
             */

            /*  Mozda ne mora, ako postoji admin panel gde se dodaje prvo mesto, pa se u editovanju tog mesta biraju hallovi
             * RuleFor(x => x.Halls)
             *  .NotEmpty()
             *  .WithMessage("There must me at least 1 hall!");
             *
             */

            /*
             * RuleForEach(x => x.Halls).
             *  SetValidator(new HallValidator(_context));
             */
        }
예제 #18
0
        public UserRoleValidator(MFGContext context)
        {
            _context = context;

            RuleFor(x => x.Id)
            .NotEmpty()
            .WithMessage("UserID is required")
            .Must(x => _context.Users.Any(u => u.Id == x))
            .WithMessage("User ID not valid");

            RuleFor(x => x.RoleID)
            .NotEmpty()
            .WithMessage("RoleID is required")
            .InclusiveBetween(1, 2)
            .WithMessage("RoleID can be 1(regular user) or 2 (seller)")
            .Must((y, x) =>
            {
                return(!(_context.Users.Find(y.Id).RoleID == 3));     // admin poskua da promeni ulogu drugom adminu
            })
            .WithMessage("You don't have permition to change another admin's role!");
        }
        public void CreateFakeUsers(int numOfUsers, MFGContext context)
        {
            ICollection <User> fakeUsers = new HashSet <User>();

            for (var i = 0; i < numOfUsers; i++)
            {
                var fakeUser = new Faker <User>()
                               .RuleFor(x => x.FirstName, f => f.Name.FirstName())
                               .RuleFor(x => x.LastName, f => f.Name.LastName())
                               .RuleFor(x => x.Username, f => f.Internet.UserName())
                               .RuleFor(x => x.Email, f => f.Internet.Email())
                               .RuleFor(x => x.Password, f => f.Internet.Password())
                               .RuleFor(x => x.CreatedAt, DateTime.UtcNow)
                               .RuleFor(x => x.IsActive, true)
                               .RuleFor(x => x.RoleID, 1);

                fakeUsers.Add(fakeUser);
            }
            context.Users.AddRange(fakeUsers);
            context.SaveChanges();
        }
        public void CreateFakeTicketResevations(MFGContext context)
        {
            ICollection <TicketReservation> ticketReservations = new HashSet <TicketReservation>();

            var users = context.Users.Where(x => x.RoleID == 1).ToList();

            int[] projectionIDs = context.Projections.Select(x => x.Id).ToArray();
            foreach (var u in users)
            {
                var numOfReservations = RandomNumber(0, 15);

                for (var i = 0; i < numOfReservations; i++)
                {
                    var projectionID = projectionIDs[RandomNumber(0, projectionIDs.Length - 1)];

                    Ticket ticket = context.Tickets.Where(x => x.ProjectionID == projectionID).FirstOrDefault();

                    var maxNumOfTickets = context.Festivals.Where(x => ticket.FestivalID == x.Id).FirstOrDefault().MaxTickets;
                    var quantity        = RandomNumber(1, maxNumOfTickets);
                    var totalPrice      = quantity * ticket.Price;
                    var code            = GenerateReservationCode(10);
                    ticketReservations.Add(
                        new TicketReservation
                    {
                        UserID          = u.Id,
                        TicketID        = ticket.Id,
                        Quantity        = quantity,
                        TotalPrice      = totalPrice,
                        ReservationDate = DateTime.UtcNow,
                        ReservationCode = code
                    }
                        );;
                }

                context.TicketReservations.AddRange(ticketReservations);
            }
            context.SaveChanges();
        }
        public DirectorCreateDtoValidator(MFGContext context)
        {
            _context = context;
            string tmp = "";

            RuleFor(x => x.FirstName)
            .NotEmpty()
            .WithMessage("First name is required")
            .MinimumLength(2)
            .WithMessage("First name must have at least 2 characters")
            .MaximumLength(20)
            .WithMessage("Maximu length for first name is 20");

            RuleFor(x => x.LastName)
            .NotEmpty()
            .WithMessage("First name is required")
            .MinimumLength(2)
            .WithMessage("First name must have at least 2 characters")
            .MaximumLength(20)
            .WithMessage("Maximu length for first name is 25");

            RuleFor(x => x.FirstName)
            .Must(n =>
            {
                if (_context.Directors.Any(x => x.FirstName.ToLower() == n))
                {
                    tmp = n;
                }
                return(true);
            });

            if (tmp != "")
            {
                RuleFor(x => x.LastName)
                .Must(ln => !_context.Directors.Any(x => x.LastName.ToLower() == ln.ToLower()))
                .WithMessage("Director with that first name and last name already exists");
            }
        }
        public void GenerateAllFakeData(MFGContext context)
        {
            // automatsko dodavanje Movie, Director, MovieDirector
            SetInitialValuesMovie(context);

            // Dodavanje Fake Festivala
            CreateFakeFestivals(context);

            //Dodavanje projekcija

            CreateFakeProjections(context);

            // dodavanje fake tickets-a

            CreateFakeTickets(context);

            // Dodavanje Fake Usera
            CreateFakeUsers(15, context);

            //  Dodavanje fake Ticket Reservationa

            CreateFakeTicketResevations(context);
        }
예제 #23
0
 public GetLocationsQuery(MFGContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public GetPlaceQuery(MFGContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public DeleteUserCommand(MFGContext context)
 {
     _context = context;
 }
 public CreateDirectorCommand(IMapper mapper, MFGContext context, DirectorCreateDtoValidator validator)
 {
     _mapper    = mapper;
     _context   = context;
     _validator = validator;
 }
 public GetTicketsQuery(MFGContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
예제 #28
0
 public EditHallCommand(MFGContext context, IMapper mapper, HallValidator validator)
 {
     _context   = context;
     _mapper    = mapper;
     _validator = validator;
 }
        public TicketReservationValidator(MFGContext context)
        {
            _context = context;

            bool     val        = false;
            Ticket   t          = new Ticket();
            Festival f          = new Festival();
            int      freeSeats  = 99999999;  // ako je greska ispisace ovo, provere radi
            int      maxTickets = 888888888; //ako je greska ispisace ovo

            RuleFor(x => x.TicketID)
            .NotNull()
            .WithMessage("TicketID field is required")
            .Must((u, p) =>
            {
                val = _context.Tickets.Any(x => x.Id == u.TicketID);
                if (val)
                {
                    /*  t = _context.Tickets.Find(u.TicketID);
                     * f = _context.Festivals.Find(t.FestivalID);
                     * maxTickets = f.MaxTickets;*/
                }
                return(val);
            })
            .WithMessage("TicketID not valid!")
            .DependentRules(() =>
            {
                RuleFor(x => x.Quantity)
                .NotEmpty()
                .WithMessage("Quantity field is required")
                .GreaterThan(0)
                .WithMessage("Minimum quantity is 1")
                .Must((x, y) =>
                {
                    t          = _context.Tickets.Find(x.TicketID);
                    f          = _context.Festivals.Find(t.FestivalID);
                    maxTickets = f.MaxTickets;
                    return(y <= maxTickets);
                })
                .WithMessage("Maximum number of tickets exceeded")
                .DependentRules(() =>
                {
                    RuleFor(x => x.Quantity)
                    .Must((u, r) =>
                    {
                        var tmp                       = true;
                        t                             = _context.Tickets.Find(u.TicketID);
                        f                             = _context.Festivals.Find(t.FestivalID);
                        var projection                = _context.Projections.FirstOrDefault(x => x.Id == t.ProjectionID);
                        var maxNumOfSeats             = _context.Halls.Where(x => x.Id == projection.HallID).Select(x => x.NumberOfSeats).FirstOrDefault();
                        var reservationsForProjection =     // _context.Tickets.Include(x=> x.TicketReservations).Where(x=>x.ProjectionID==t.ProjectionID).Count()
                                                        _context.TicketReservations.Where(x => x.TicketID == t.Id && x.Id != u.Id).ToList();

                        var reservedSeats = 0;

                        foreach (var i in reservationsForProjection)
                        {
                            reservedSeats += i.Quantity;
                        }

                        freeSeats = maxNumOfSeats - reservedSeats;
                        if (u.Quantity > freeSeats)
                        {
                            tmp = false;
                        }
                        return(tmp);
                    })
                    // .WithMessage("There is only " + freeSeats + " free seats left");
                    .WithMessage("There is fewer free seats left than you requested");
                });
            });

            /*  RuleFor(x => x.UserID)
             *       .NotNull()
             *       .WithMessage("UserID field is required")
             *       .Must(p => _context.Users.Any(x => x.Id == p))
             *       .WithMessage("UserID not valid!");
             *
             * RuleFor(x => x)
             *
             *    .Must((x) =>
             *    {
             *        //    var ticket = _context.Tickets.Include(x.)
             *        var ticket = _context.Tickets.Find(x.TicketID);
             *        var festival = _context.Festivals.Find(ticket.FestivalID);
             *
             *        var projection = _context.Projections.FirstOrDefault(x => x.Id == ticket.ProjectionID);
             *        var maxNumOfSeats = _context.Halls.Where(x => x.Id == projection.HallID).Select(x => x.NumberOfSeats).FirstOrDefault();
             *        var reservationsForProjection =// _context.Tickets.Include(x=> x.TicketReservations).Where(x=>x.ProjectionID==t.ProjectionID).Count()
             *          _context.TicketReservations.Where(x => x.TicketID == ticket.Id).ToList();
             *
             *        var reservedSeats = 0;
             *
             *        foreach (var i in reservationsForProjection)
             *        {
             *            reservedSeats += i.Quantity;
             *        }
             *
             *        freeSeats = maxNumOfSeats - reservedSeats;
             *        // if (x.Quantity > freeSeats) tmp = false;
             *        return x.Quantity > freeSeats;
             *    })
             *    .WithMessage()*/

            /*
             *
             *          bool val = false;
             *          Ticket t = new Ticket();
             *          Festival f = new Festival();
             *
             *          RuleFor(x => x.TicketID)
             *             .NotNull()
             *             .WithMessage("TicketID field is required")
             *             .Must(p =>
             *             {
             *                 val = _context.Tickets.Any(x => x.Id == p);
             *                 if (val)
             *                 {
             *                     t = _context.Tickets.FirstOrDefault(x => x.Id == p);
             *                     f = _context.Festivals.FirstOrDefault(x => x.Id == t.FestivalID);
             *                 }
             *                 return val;
             *             })
             *             .WithMessage("TicketID not valid!");
             *
             *          RuleFor(x => x.UserID)
             *                 .NotNull()
             *                 .WithMessage("UserID field is required")
             *                 .Must(p => _context.Users.Any(x => x.Id == p))
             *                 .WithMessage("UserID not valid!");
             *
             *          if (val)
             *          {
             *              int freeSeats = 99999999; // ako je greska ispisace ovo, provere radi
             *              RuleFor(x => x.Quantity)
             *                .NotNull()
             *                .WithMessage("Quantity field is required")
             *                .GreaterThan(0)
             *                .WithMessage("Minimum quantity is 1")
             *                .LessThan(f.MaxTickets + 1)
             *                .WithMessage("Maximum number of tickets per reservation is " + f.MaxTickets)
             *                .Must(r =>
             *                {
             *                    var tmp = true;
             *                    var projection = _context.Projections.FirstOrDefault(x => x.Id == t.ProjectionID);
             *                    var maxNumOfSeats = _context.Halls.Where(x => x.Id == projection.HallID).Select(x => x.NumberOfSeats).FirstOrDefault();
             *                    var reservationsForProjection =// _context.Tickets.Include(x=> x.TicketReservations).Where(x=>x.ProjectionID==t.ProjectionID).Count()
             *                      _context.TicketReservations.Where(x => x.TicketID == t.Id).ToList();
             *
             *                    var reservedSeats = 0;
             *
             *                    foreach (var i in reservationsForProjection)
             *                    {
             *                        reservedSeats += i.Quantity;
             *                    }
             *
             *                    freeSeats = maxNumOfSeats - reservedSeats;
             *                    if (r > freeSeats) tmp = false;
             *                    return tmp;
             *                })
             *                .WithMessage("There is only " + freeSeats + " free seats left");
             *          }*/
        }
 public CreateTicketCommand(MFGContext context, IMapper mapper, TicketCreateDtoValidator validator)
 {
     _context = context;
     _mapper = mapper;
     _validator = validator;
 }