Exemplo n.º 1
0
 public PMSeatsVM()
 {
     using (CondorDBContextChild principal = new CondorDBContextChild(HttpContext.Current.Session["ConnectionString"].ToString()))
     {
         SeatRow = principal.SeatRows.ToList();
     }
 }
Exemplo n.º 2
0
        public ActionResult CancelReservation(int reservationID, string connectionString)
        {
            // Find the desired local reservation
            CondorDBContextChild localContext = new CondorDBContextChild(connectionString);
            var reservation = localContext.Reservations.Find(reservationID);

            // Mark it as deleted (canceled)
            reservation.IsDeleted = true;
            localContext.SaveChanges();

            return(RedirectToAction("Index", "RegisteredVisitor"));
        }
Exemplo n.º 3
0
        public static void StartNewSession(Employee Em, HttpContextBase Context, bool RememberMe)
        {
            if (Em == null)
            {
                Context.Session.Add(loggedUser, Em);
                return;
            }
            using (CondorDBContextChild principal = new CondorDBContextChild(HttpContext.Current.Session["ConnectionString"].ToString()))
            {
                List <EmployeeRole> EmployeeRoles = new List <EmployeeRole>();
                EmployeeRoles = principal.EmployeesRoles.Where(x => x.EmployeeID == Em.EmployeeID).ToList();
                EmployeeRoles = EmployeeRoles.OrderBy(x => x.RoleID).ToList();

                Dictionary <string, int> RoleName = new Dictionary <string, int>();

                foreach (Role r in principal.Roles)
                {
                    RoleName.Add(r.RoleName, r.RoleID);
                }

                Dictionary <int, string> paths = new Dictionary <int, string>
                {
                    { RoleName["Director"], "/../Local/Director" },
                    { RoleName["ProjectionManager"], "/../Local/ProjectionManager" },
                    { RoleName["Employee"], "/../Local/Employee" }
                };

                for (int i = 0; i < paths.Count; i++)
                {
                    if (!EmployeeRoles.Where(e => e.RoleID == paths.Keys.ElementAt(i)).Any())
                    {
                        paths.Remove(paths.Keys.ElementAt(i)); i--;
                    }
                }


                Context.Session.Add(loggedUser, Em);


                HttpContext.Current.Session["paths"] = paths as Dictionary <int, string>;


                if (RememberMe)
                {
                    HttpCookie cookie = new HttpCookie("CondorExtreme3Cookie", Em.EmployeeID.ToString());
                    cookie.Expires = DateTime.Now.AddDays(5);
                    Context.Response.Cookies.Add(cookie);
                }
            }
        }
Exemplo n.º 4
0
        public AddProjectionVM()
        {
            using (CondorDBContextChild principal = new CondorDBContextChild(HttpContext.Current.Session["ConnectionString"].ToString()))
            {
                Genres = principal.Genres.Select(x => new SelectListItem
                {
                    Text  = x.GenreName,
                    Value = x.GenreID.ToString()
                }).ToList();

                Actors = principal.Actors.Select(x => new SelectListItem
                {
                    Text  = x.FirstName + " " + x.LastName,
                    Value = x.ActorID.ToString()
                }).ToList();

                Directors = principal.Directors.Select(x => new SelectListItem
                {
                    Text  = x.FirstName + " " + x.LastName,
                    Value = x.DirectorID.ToString()
                }).ToList();

                Movies = principal.Movies.Select(x => new SelectListItem
                {
                    Text  = x.OriginalName + "(" + x.MovieName + ")",
                    Value = x.MovieID.ToString()
                }).ToList();

                CinemaHalls = principal.CinemaHalls.Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.CinemaHallID.ToString()
                }).ToList();

                DateTimeStarts = principal.DefinedDateTimes.Select(x => new SelectListItem
                {
                    Text  = x.DateTimeStart.ToString(),
                    Value = x.DateTimeStart.ToString()
                }).ToList();

                TechTypes = principal.TechnologyTypes.Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.TechnologyTypeID.ToString()
                }).ToList();
            }
        }
Exemplo n.º 5
0
        public ActionResult ConfirmReservation(int reservationID, string connectionString)
        {
            // Find the desired local reservation
            CondorDBContextChild localContext = new CondorDBContextChild(connectionString);
            // Find the desired global user
            var globalUser  = contextGlobal.RegisteredVisitors.Find(Session["UserID"]);
            var reservation = localContext.Reservations.Find(reservationID);
            // Calculate the price as the sum of all ticket prices in the reservation
            var reservationPrice = reservation.Tickets.Sum(x => x.TotalTicketPrice);

            // The user has enough to proceed
            if (globalUser.VirtualPointsTotal >= reservationPrice)
            {
                reservation.ReservationCompleted = true;
                globalUser.VirtualPointsTotal   -= (int)reservationPrice;
                localContext.SaveChanges();
                contextGlobal.SaveChanges();
            }

            return(RedirectToAction("Index", "RegisteredVisitor"));
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Runs through all user reservations (global level)
        ///     and finds the corresponding local reservations (cinema level).
        /// </summary>
        /// <returns>List of (local level) reservations.</returns>
        private List <Models.ReservationVM> GetForeignReservations()
        {
            // Find all global (user) reservations
            var globalReservations = contextGlobal.Reservations
                                     .Where(x => x.ConnString != null)
                                     .ToList();

            // Create a list of foreign reservations
            var foreignReservations = new List <Models.ReservationVM>();

            foreach (var reservation in globalReservations)
            {
                var tempConnection = new CondorDBContextChild(reservation.ConnString);
                // Where the GUID of the reservation matches the global GUID
                var foreignReservation = tempConnection.Reservations
                                         .Where(x => x.Guid == reservation.Guid)
                                         .FirstOrDefault();

                if (foreignReservation != null)
                {
                    var newReservation = new Models.ReservationVM
                    {
                        ReservationID   = foreignReservation.ReservationID,
                        ReservationDate = foreignReservation.ReservationDate,
                        ExpiryDate      = foreignReservation.ExpiryDate,
                        Status          = foreignReservation.ReservationCompleted ?
                                          "Approved" : foreignReservation.IsDeleted ?
                                          "Canceled" : "Pending",
                        Discount         = foreignReservation.Tickets.Sum(x => x.TotalDiscountAmount),
                        Total            = foreignReservation.Tickets.Sum(x => x.TotalTicketPrice),
                        ConnectionString = reservation.ConnString
                    };

                    foreignReservations.Add(newReservation);
                }
            }

            return(foreignReservations);
        }
Exemplo n.º 7
0
        // Kill me please..
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            CondorDBContextChild db = new CondorDBContextChild(HttpContext.Current.Session["ConnectionString"].ToString());

            var className     = this.type.Name + "s";
            var propertyName  = validationContext.MemberName;
            var parameterName = string.Format("@{0}", propertyName);

            // Kill me please..
            var result = db.Database.SqlQuery <int>(
                string.Format("SELECT COUNT(*) FROM {0} WHERE {1}={2}", className, propertyName, parameterName),
                new System.Data.SqlClient.SqlParameter(parameterName, value));

            // Kill me please..
            if (result.ToList()[0] > 0)
            {
                return(new ValidationResult(string.Format(this.ErrorMessage)));
            }

            // End my suffering
            return(null);
        }
Exemplo n.º 8
0
        public static Employee GetLoggedEmployee(HttpContextBase context)
        {
            Employee Em = (Employee)context.Session[loggedUser];

            if (Em != null)
            {
                return(Em);
            }

            HttpCookie cookie = context.Request.Cookies.Get("CondorExtreme3Cookie");

            if (cookie == null)
            {
                return(null);
            }

            int EiD;

            try
            {
                EiD = Int32.Parse(cookie.Value);
            }
            catch
            {
                return(null);
            }
            using (CondorDBContextChild principal = new CondorDBContextChild(HttpContext.Current.Session["ConnectionString"].ToString()))
            {
                Employee e = principal.Employees
                             .Where(x => x.EmployeeID == EiD)
                             .FirstOrDefault();

                StartNewSession(e, context, true);
                return(e);
            }
        }
Exemplo n.º 9
0
        public AddCinemaVM()
        {
            CondorDBContextChild principal = new CondorDBContextChild(HttpContext.Current.Session["ConnectionString"].ToString());

            Countries = principal.Country.Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.CountryID.ToString()
            }).ToList();

            Cities = principal.Cities.Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.CityID.ToString()
            }).ToList();

            Addreses = principal.Addresses.Select(x => new SelectListItem()
            {
                Text  = x.AddressLine1,
                Value = x.AddressID.ToString()
            }).ToList();

            TechTypes = principal.TechnologyTypes.ToList();
        }
Exemplo n.º 10
0
        /// <summary>
        ///     RegisteredVisitor index page
        /// </summary>
        /// <param name="seats">String in format "ProjectionID, Seat1, Seat2, Seatn"</param>
        /// <param name="ProjectionId">ID of the projection</param>
        /// <returns></returns>
        public ActionResult Index(string seats = "", string ProjectionId = "")
        {
            // In case we are redirected from main page and need to make a reservation
            if (seats != "" && ProjectionId != "")
            {
                // At this point ProjectionId is redundant as you get it within seats
                // Fix this at a later time

                // Get all seats
                List <string> AllSeats = seats.Trim(',').Split(',').ToList();
                ModelsUser.RegisteredVisitor visitor = contextGlobal.RegisteredVisitors.Find(int.Parse(Session["UserID"].ToString()));

                // Use local context (this cinema instance)
                using (CondorDBContextChild contextLocal = new CondorDBContextChild(HttpContext.Session["ConnectionString"].ToString()))
                {
                    // Check if local cinema has this users country/city
                    if (!contextLocal.Cities.Any(x => x.Name == visitor.City.Name))
                    {
                        // If not make the country first
                        ModelsLocalDB.Country co = new ModelsLocalDB.Country();

                        // If the country doesn't exist
                        if (!contextLocal.Country.Any(x => x.Name == visitor.City.Country.Name))
                        {
                            // Add it to the local database
                            co = new ModelsLocalDB.Country()
                            {
                                Name      = visitor.City.Country.Name,
                                IsDeleted = false
                            };

                            contextLocal.Country.Add(co);
                            contextLocal.SaveChanges();
                        }

                        // Repeat the same for the user city
                        ModelsLocalDB.City ci = new ModelsLocalDB.City()
                        {
                            CityID     = visitor.CityID,
                            Name       = visitor.City.Name,
                            PostalCode = visitor.City.PostalCode,
                            IsDeleted  = false,
                            CountryID  = co.CountryID,
                            Country    = co
                        };

                        contextLocal.Cities.Add(ci);
                        contextLocal.SaveChanges();
                    }

                    // Check if this user exists in the local cinema (cross DB hence GUID)
                    // The user exists only if he reserved in this cinema previously
                    if (!contextLocal.RegisteredVisitors.Any(x => x.Guid == visitor.Guid))
                    {
                        // If the user doesn't exist copy him over with basic information
                        ModelsLocalDB.RegisteredVisitor localRV = new ModelsLocalDB.RegisteredVisitor();

                        // Do not copy username or password here for security reasons
                        localRV.RegisteredVisitorID = int.Parse(Session["UserID"].ToString());
                        localRV.FirstName           = visitor.FirstName;
                        localRV.LastName            = visitor.LastName;
                        localRV.PhoneNumber         = visitor.PhoneNumber;
                        localRV.Email = visitor.Email;
                        // Make sure to copy over the GUID for the next search
                        localRV.Guid   = visitor.Guid;
                        localRV.CityID = contextLocal.Cities
                                         .Any(x => x.Name == visitor.City.Name) ?
                                         contextLocal.Cities.Where(x => x.Name == visitor.City.Name)
                                         .SingleOrDefault().CityID : visitor.CityID;

                        contextLocal.RegisteredVisitors.Add(localRV);
                        contextLocal.SaveChanges();
                    }

                    // Create a new reservation (locally in the cinema)
                    ModelsLocalDB.Reservation r = new ModelsLocalDB.Reservation();
                    // Create a mirror on the (globally in the users database)
                    ModelsUser.Reservation r_mirror = new ModelsUser.Reservation();

                    r.RegisteredVisitorID  = visitor.RegisteredVisitorID;
                    r.ProjectionID         = int.Parse(ProjectionId);
                    r.PaymentMethod        = contextLocal.PaymentMethods.FirstOrDefault();
                    r.IsDeleted            = false;
                    r.ReservationDate      = contextLocal.Projections.Find(r.ProjectionID).DateTimeStart;
                    r.ExpiryDate           = contextLocal.Projections.Find(r.ProjectionID).DateTimeStart.Subtract(new TimeSpan(0, 30, 0));
                    r.ReservationCompleted = false;
                    // Create a new GUID
                    r.Guid = Guid.NewGuid().ToString();

                    // Copy the basic information to the mirror
                    r_mirror.ConnString          = HttpContext.Session["ConnectionString"].ToString();
                    r_mirror.RegisteredVisitor   = visitor;
                    r_mirror.RegisteredVisitorID = visitor.RegisteredVisitorID;
                    // Copy the GUID of the previously created reservation
                    r_mirror.Guid = r.Guid;

                    contextLocal.Reservations.Add(r);
                    contextLocal.SaveChanges();

                    contextGlobal.Reservations.Add(r_mirror);
                    contextGlobal.SaveChanges();

                    // Foreach seat (skip the first parameter ProjectID)
                    foreach (string seat in AllSeats.Skip(1))
                    {
                        // Find the projection
                        var projectionSeat = contextLocal.ProjectionSeats
                                             .Find(int.Parse(ProjectionId), int.Parse(seat));

                        projectionSeat.IsReserved = true;
                        // Create the ticket for the seat
                        ModelsLocalDB.Ticket ticket = new ModelsLocalDB.Ticket();

                        ticket.SeatID              = projectionSeat.SeatID;
                        ticket.TicketPrice         = projectionSeat.Projection.TicketPrice;
                        ticket.TotalTicketPrice    = ticket.TicketPrice;
                        ticket.TotalDiscountAmount = 0;
                        ticket.IsSold              = false;
                        ticket.IsDeleted           = false;
                        ticket.ReservationID       = r.ReservationID;

                        contextLocal.Tickets.Add(ticket);
                    }

                    contextLocal.SaveChanges();
                }

                // Redirect to login if user is not logged
                if (Session["UserID"] == null)
                {
                    return(RedirectToAction("Login"));
                }
            }

            return(View());
        }