Beispiel #1
0
        public void AddPerformanceOrder(int orderId)
        {
            var success  = false;
            var mediator = new TicketMediator();
            var cart     = mediator.GetCart();

            using (var db = new ManagementToolProjectEntities())
            {
                foreach (var perf in cart.Performances)
                {
                    var perfOrder = new OrderPerformanceMapping2
                    {
                        OderId        = orderId,
                        PerformanceId = perf.PerformanceId,
                        Quantity      = perf.Quantity
                    };

                    db.OrderPerformanceMapping2.Add(perfOrder);
                    success = db.SaveChanges() > 0;

                    if (success)
                    {
                        var performance = mediator.GetPerformance(perf.PerformanceId);
                        performance.AvailableTickets = performance.AvailableTickets - perf.Quantity;
                        success = mediator.UpdatePerformance(performance);
                    }
                }
            }
        }
Beispiel #2
0
        public bool RegisterUser(RegisterVM reg)
        {
            var success = false;

            using (var db = new ManagementToolProjectEntities())
            {
                bool emailExist = db.Users.FirstOrDefault(u => u.EmailAddress == reg.Email) != null;

                if (!emailExist)
                {
                    var regUser = new User
                    {
                        EmailAddress = reg.Email.Trim().ToLower(),
                        FirstName    = reg.FirstName,
                        LastName     = reg.LastName,
                        Password     = reg.Password,
                        status       = true
                    };
                    db.Users.Add(regUser);
                    success = db.SaveChanges() > 0;
                }
            }

            return(success);
        }
Beispiel #3
0
        public bool CreateOrder(PaymentVM payment)
        {
            var success  = false;
            var mediator = new TicketMediator();
            var cart     = mediator.GetCart();

            foreach (var perf in cart.Performances)
            {
                var performance = mediator.GetPerformance(perf.PerformanceId);

                if (performance.AvailableTickets - perf.Quantity >= 0)
                {
                    success = true;

                    if (!success)
                    {
                        break;
                    }
                }
            }

            if (success)
            {
                using (var db = new ManagementToolProjectEntities())
                {
                    var date   = payment.ExpirationMonth + "/1/" + payment.ExpirationYear;
                    var expiry = DateTime.Parse(date);

                    var orderModel = new Order
                    {
                        FirstName       = payment.FirstName,
                        LastName        = payment.LastName,
                        BillingAdress   = payment.BillingAddress.Address1,
                        BillingCity     = payment.BillingAddress.City,
                        BillingState    = payment.BillingAddress.State,
                        BillingZipCode  = Convert.ToInt32(payment.BillingAddress.Zip),
                        ShippingAdress  = payment.ShippingAddress.Address1,
                        ShippingCity    = payment.ShippingAddress.City,
                        ShippingState   = payment.ShippingAddress.State,
                        ShippingZipCode = Convert.ToInt32(payment.ShippingAddress.Zip),
                        ExpirationDate  = expiry,
                        CreditCard      = payment.CreditCardNumber,
                        status          = 1
                    };

                    var order = db.Orders.Add(orderModel);
                    success = db.SaveChanges() > 0;

                    if (success)
                    {
                        AddPerformanceOrder(order.OrderId);
                    }
                }
            }

            return(success);
        }
Beispiel #4
0
        public List <PerformanceVM> GetUpcomingPerformances()
        {
            var performances = new List <PerformanceVM>();

            using (var db = new ManagementToolProjectEntities())
            {
                var resp  = new PerformanceRepository(db);
                var perfs = resp.Get(p => p.Date > DateTime.Now && p.Event.status == 1).OrderBy(o => o.Date).Take(5);

                var transformer = new PerformanceTransformer();
                performances = transformer.Transform(perfs);
            }
            return(performances);
        }
Beispiel #5
0
        public EventVM GetEvent(int id)
        {
            var ev = new EventVM();

            using (var db = new ManagementToolProjectEntities())
            {
                var   resp    = new EventRepository(db);
                Event dbEvent = db.Events.FirstOrDefault(e => e.EventId == id);

                var transformer = new EventTransformer();
                ev = transformer.Transform(dbEvent);
            }
            return(ev);
        }
Beispiel #6
0
        public PerformanceVM GetPerformance(int id)
        {
            var performance = new PerformanceVM();

            using (var db = new ManagementToolProjectEntities())
            {
                var resp        = new PerformanceRepository(db);
                var perf        = resp.GetFirstOrDefault(p => p.PerformanceId == id);
                var transformer = new PerformanceTransformer();
                performance = transformer.Transform(perf);
            }

            return(performance);
        }
Beispiel #7
0
        public List <PerformanceVM> GetPerformances(int id)
        {
            var performances = new List <PerformanceVM>();

            using (var db = new ManagementToolProjectEntities())
            {
                var resp  = new PerformanceRepository(db);
                var perfs = resp.Get(p => p.EventId == id);

                var transformer = new PerformanceTransformer();
                performances = transformer.Transform(perfs);
            }
            return(performances);
        }
Beispiel #8
0
        public List <EventVM> GetActiveEvents()
        {
            var events = new List <EventVM>();

            using (var db = new ManagementToolProjectEntities())
            {
                var resp = new EventRepository(db);
                IEnumerable <Event> dbEvents = resp.Get(e => e.status == 1);

                var transformer = new EventTransformer();
                events = transformer.Transform(dbEvents);
            }

            return(events);
        }
Beispiel #9
0
        public List <Category> GetEventTypes()
        {
            var eventTypes = new List <Category>();

            using (var db = new ManagementToolProjectEntities())
            {
                var resp  = new EventTypeRepository(db);
                var types = resp.GetAll().ToList();

                var transformer = new CategoryTransformer();
                eventTypes = transformer.Transform(types);
            }

            return(eventTypes);
        }
Beispiel #10
0
        public bool Authenticate(RegisterVM user)
        {
            bool isAuthenticated = false;

            using (var db = new ManagementToolProjectEntities())
            {
                var account = db.Users.FirstOrDefault(u => u.EmailAddress.Trim().ToLower() == user.Email.Trim().ToLower());

                if (account != null)
                {
                    if (user.Password == account.Password)
                    {
                        isAuthenticated = true;
                    }
                }
            }

            return(isAuthenticated);
        }
Beispiel #11
0
        public bool UpdatePerformance(PerformanceVM model)
        {
            var success = false;

            using (var db = new ManagementToolProjectEntities())
            {
                var         resp = new PerformanceRepository(db);
                Performance perf = resp.GetFirstOrDefault(p => p.PerformanceId == model.PerformanceId);

                perf.Date         = DateTime.Parse(model.PerformanceDate);
                perf.Price        = model.Price;
                perf.status       = model.Cancelled;
                perf.TotalTickets = model.AvailableTickets;
                perf.EventId      = model.EventId;

                resp.Update(perf);
                success = db.SaveChanges() > 0;
            }

            return(success);
        }
Beispiel #12
0
        public bool UpdateEvent(EventVM model)
        {
            var success = false;

            using (var db = new ManagementToolProjectEntities())
            {
                var   resp    = new EventRepository(db);
                Event dbEvent = db.Events.FirstOrDefault(e => e.EventId == model.Id);

                dbEvent.Description = model.Description;
                dbEvent.Image       = model.Image;
                dbEvent.Location    = model.Location;
                dbEvent.Name        = model.Name;
                dbEvent.status      = Convert.ToInt32(model.Active);

                resp.Update(dbEvent);
                success = db.SaveChanges() > 0;
            }

            return(success);
        }
Beispiel #13
0
        public bool CreateEvent(EventVM model)
        {
            var success = false;

            using (var db = new ManagementToolProjectEntities())
            {
                var eventModel = new Event
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Location    = model.Location,
                    Image       = model.Image,
                    status      = Convert.ToInt32(model.Active),
                    EventTypeId = model.Category
                };

                db.Events.Add(eventModel);
                success = db.SaveChanges() > 0;
            }

            return(success);
        }
Beispiel #14
0
        public bool CreatePerformance(PerformanceVM model)
        {
            var success = false;

            using (var db = new ManagementToolProjectEntities())
            {
                var resp = new PerformanceRepository(db);

                var perf = new Performance
                {
                    Date         = DateTime.Parse(model.PerformanceDate),
                    EventId      = model.EventId,
                    Price        = model.Price,
                    status       = model.Cancelled,
                    TotalTickets = model.AvailableTickets
                };

                resp.Insert(perf);
                success = db.SaveChanges() > 0;
            }

            return(success);
        }