Ejemplo n.º 1
0
        public void CheckIfReservationIsInPast_ItIsNotPast_False()
        {
            ReservationController sac = new ReservationController();
            string time   = "00:00 PM";
            string vreme1 = "4/20/2018" + " " + time;
            var    input  = new ProjectionWithFlagViewModel()
            {
                isCancelable = false,
                Karta        = new Ticket()
                {
                    Projection = new HallTimeProjection()
                    {
                        Time = DateTime.Parse(vreme1),
                    }
                }
            };

            var contextMock           = new Mock <HttpContextBase>();
            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.Setup(con => con.HttpContext).Returns(contextMock.Object);

            sac.ControllerContext = controllerContextMock.Object;
            var result = sac.checkIfReservationIsInPast(input);

            Assert.That(result, Is.False);
        }
Ejemplo n.º 2
0
        public void CheckIfReservationIsInPast_ItIsInPast_True()
        {
            ReservationController sac = new ReservationController();
            var input = new ProjectionWithFlagViewModel()
            {
                isCancelable = false,
                Karta        = new Ticket()
                {
                    Projection = new HallTimeProjection()
                    {
                        Time = new DateTime(),
                    }
                }
            };

            var contextMock           = new Mock <HttpContextBase>();
            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.Setup(con => con.HttpContext).Returns(contextMock.Object);

            sac.ControllerContext = controllerContextMock.Object;
            var result = sac.checkIfReservationIsInPast(input);

            Assert.That(result, Is.True);
        }
Ejemplo n.º 3
0
        public bool checkIfReservationIsInPast(ProjectionWithFlagViewModel reservation)
        {
            DateTime now    = DateTime.Now;
            bool     RetVal = false;

            if (DateTime.Compare(now, reservation.Karta.Projection.Time) < 0)
            {
                RetVal = false;
            }
            else
            {
                RetVal = true;
            }

            return(RetVal);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> ShowReservations()
        {
            ApplicationDbContext ctx = ApplicationDbContext.Create();
            String id      = User.Identity.GetUserId();
            Guid   idUsera = new Guid(id);
            var    userWithReservations = await ctx.Users.Include(x => x.ReservationsList).FirstOrDefaultAsync(x => x.Id == id);

            List <ProjectionWithFlagViewModel> reservations = new List <ProjectionWithFlagViewModel>();

            foreach (Ticket res in userWithReservations.ReservationsList)
            {
                Ticket resWithProjection = await ctx.Reservations.Include(x => x.Projection).FirstOrDefaultAsync(x => x.Id == res.Id);

                var mama = await ctx.HallTimeProjection.Include(x => x.Seats).FirstOrDefaultAsync(x => x.Id == res.Projection.Id);

                var saHalom = await ctx.HallTimeProjection.Include(x => x.Hall).FirstOrDefaultAsync(x => x.Id == mama.Id);

                var saProjekcijom = await ctx.HallTimeProjection.Include(x => x.Projection).FirstOrDefaultAsync(x => x.Id == mama.Id);

                var hala            = ctx.Database.SqlQuery <Hall>("select * from Halls where Id = '" + resWithProjection.Projection.Hall.Id + "'").FirstOrDefault();
                var halaSaLokacijom = await ctx.Halls.Include(x => x.ParentLocation).FirstOrDefaultAsync(x => x.Id == resWithProjection.Projection.Hall.Id);

                resWithProjection.Projection.Hall = halaSaLokacijom;
                var saSedistima = await ctx.HallTimeProjection.Include(x => x.Seats).FirstOrDefaultAsync(x => x.Id == resWithProjection.Projection.Id);

                resWithProjection.Projection = saSedistima;

                DateTime now          = DateTime.Now;
                bool     isCancelable = true;
                if (now.Date.Equals(resWithProjection.Projection.Time.Date) && now.TimeOfDay.Hours.Equals(resWithProjection.Projection.Time.TimeOfDay.Hours))
                {
                    if (resWithProjection.Projection.Time.TimeOfDay.Minutes - now.TimeOfDay.Minutes < 30)
                    {
                        isCancelable = false;
                    }
                    else
                    {
                        isCancelable = true;
                    }
                }
                else
                {
                    ProjectionWithFlagViewModel forCheck = new ProjectionWithFlagViewModel
                    {
                        Karta        = resWithProjection,
                        isCancelable = true
                    };
                    if (checkIfReservationIsInPast(forCheck))
                    {
                        isCancelable = false;
                    }
                    else
                    {
                        isCancelable = true;
                    }
                }
                ProjectionWithFlagViewModel vm = new ProjectionWithFlagViewModel
                {
                    Karta        = resWithProjection,
                    isCancelable = isCancelable
                };
                reservations.Add(vm);
            }
            List <ProjectionWithFlagViewModel> sve = new List <ProjectionWithFlagViewModel>();

            foreach (ProjectionWithFlagViewModel t in reservations)
            {
                sve.Add(t);
            }
            List <ProjectionWithFlagViewModel> preciscene  = removeSameProjectionTickets(reservations);
            List <ProjectionWithFlagViewModel> izProslosti = new List <ProjectionWithFlagViewModel>();

            foreach (ProjectionWithFlagViewModel proj in preciscene)
            {
                if (checkIfReservationIsInPast(proj))
                {
                    izProslosti.Add(proj);
                }
            }
            List <Location> visitedPlaces = findVisitHistory(preciscene);
            var             visited       = new List <SelectListItem>();

            foreach (Location posecena in visitedPlaces)
            {
                visited.Add(new SelectListItem {
                    Text = posecena.Name, Value = posecena.Name
                });
            }
            ViewBag.visitedPlaces = visited;
            ViewBag.preciscene    = izProslosti;
            return(View("ShowReservations", sve));
        }