Exemple #1
0
        public ActionResult Pay()
        {
            Order  order      = new Order();
            double?totalPrice = 0.0;

            foreach (string reqName in Request.Form.AllKeys)
            {
                try
                {
                    int         n    = Convert.ToInt32(reqName);
                    Ticket_Game tg   = _context.Ticket_Game.Single(m => m.Id == n);
                    var         name = Request.Form[reqName];
                    totalPrice += tg.Price;
                    tg.Name     = name;
                    tg.Sold     = 1;
                    Order_Ticket_Game otg = new Order_Ticket_Game(tg.Id, order.Id);
                    _context.Order_Ticket_Game.Add(otg);
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                }
            }
            order.Total  = (double)totalPrice;
            order.Date   = DateTime.Now;
            order.UserId = User.Identity.GetUserId();
            _context.Orders.Add(order);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Order"));
        }
Exemple #2
0
        public void Pay(string tgs)
        {
            string[] pairs = tgs.Split(',');
            Dictionary <int, string> dict = new Dictionary <int, string>();

            foreach (string pair in pairs)
            {
                string[] broken = pair.Split('-');
                int      tgId   = Convert.ToInt32(broken[0]);
                string   tgName = broken[1];
                dict.Add(tgId, tgName);
            }

            Order  order      = new Order();
            double?totalPrice = 0.0;

            foreach (int i in dict.Keys)
            {
                try
                {
                    int         n  = i;
                    Ticket_Game tg = _context.Ticket_Game.Single(m => m.Id == n);
                    totalPrice += tg.Price;
                    tg.Name     = dict[i];
                    tg.Sold     = 1;
                    Order_Ticket_Game otg = new Order_Ticket_Game(tg.Id, order.Id);
                    _context.Order_Ticket_Game.Add(otg);
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                }
            }
            order.Total  = (double)totalPrice;
            order.Date   = DateTime.Now;
            order.UserId = User.Identity.GetUserId();
            _context.Orders.Add(order);
            _context.SaveChanges();
        }
        public ActionResult Save(ReviewFormViewModel vm)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            if (!ModelState.IsValid)
            {
                //foreach (ModelState modelState in ViewData.ModelState.Values)
                //{
                //    foreach (ModelError error in modelState.Errors)
                //    {
                //        return Content(error.ErrorMessage);
                //    }
                //}
                return(View("Form", vm));
            }

            if (vm.Id == 0)
            {
                var currentUserId = User.Identity.GetUserId();
                var review        = new Review
                {
                    Id          = vm.Id,
                    Comment     = vm.Comment,
                    Rating      = vm.Rating,
                    UserId      = currentUserId,
                    DateWritten = DateTime.Now,
                };
                _context.Reviews.Add(review);
            }
            else
            {
                var reviewInDb = _context.Reviews.Single(c => c.Id == vm.Id);
                reviewInDb.Comment = vm.Comment;
                reviewInDb.Rating  = vm.Rating;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Review"));
        }
Exemple #4
0
        public ActionResult Save(TicketFormViewModel vm, HttpPostedFileBase postedFile)
        {
            //Ticket ticket = vm.Ticket;
            if (!ModelState.IsValid)
            {
                //foreach (ModelState modelState in ViewData.ModelState.Values)
                //{
                //    foreach (ModelError error in modelState.Errors)
                //    {
                //        return Content(error.ErrorMessage);
                //    }
                //}
                var viewModel = new TicketFormViewModel
                {
                    Owner      = vm.Owner,
                    CategoryId = vm.CategoryId,
                    Section    = vm.Section,
                    Seat       = vm.Seat,
                    Row        = vm.Row,
                    ViewUpload = vm.ViewUpload,
                    Categories = _context.Ref_Category.ToList()
                };
                return(View("Form", viewModel));
            }

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName.Replace(' ', '_')));
            }

            Dictionary <int, double> Prices = new Dictionary <int, double>();
            bool   editMode = false;
            Ticket ticket   = null;

            if (vm.Id == 0)
            {
                ticket = new Ticket()
                {
                    Id         = vm.Id,
                    CategoryId = vm.CategoryId,
                    Section    = vm.Section,
                    Row        = vm.Row,
                    Seat       = vm.Seat,
                    Owner      = vm.Owner
                };
                if (postedFile != null)
                {
                    ticket.ViewUpload = postedFile.FileName.Replace(' ', '_');
                }

                _context.Tickets.Add(ticket);
            }
            else
            {
                editMode = true;


                var ticketInDb = _context.Tickets.Single(c => c.Id == vm.Id);
                ticketInDb.Owner      = vm.Owner;
                ticketInDb.CategoryId = vm.CategoryId;
                ticketInDb.Section    = vm.Section;
                ticketInDb.Row        = vm.Row;
                ticketInDb.Seat       = vm.Seat;
                if (postedFile != null)
                {
                    ticketInDb.ViewUpload = postedFile.FileName.Replace(' ', '_');
                }
                string query       = "Select GameId, Price From Ticket_Game Where Sold = 0 and TicketId = " + ticketInDb.Id + ";";
                var    game_prices = _context.Database.SqlQuery <GamePricePair>(query).ToList();
                foreach (GamePricePair tp in game_prices)
                {
                    Prices.Add(tp.GameId, tp.Price);
                }
                //remove existing data
                //_context.Database.ExecuteSqlCommand("Delete from Ticket_Game Where Sold=0 and TicketId = " + ticket.Id);
                var toRemove = _context.Ticket_Game.Where(m => m.TicketId == vm.Id && m.Sold == 0);
                _context.Ticket_Game.RemoveRange(toRemove);

                if (vm.ViewUpload != null)
                {
                    ticketInDb.ViewUpload = vm.ViewUpload.Replace(' ', '_');
                }
                //else keep same
                ticket = ticketInDb;
            }

            _context.SaveChanges();
            if (vm.SelectedGames != null)
            {
                foreach (string s in vm.SelectedGames)
                {
                    double price = 0;
                    var    game  = _context.Games.SingleOrDefault(m => m.Id.ToString() == s);
                    if (editMode)
                    {
                        if (Prices.ContainsKey(game.Id))
                        {
                            price = Prices[game.Id];
                        }
                        else
                        {
                            switch (ticket.CategoryId)
                            {
                            case 1: price = 250; break;    //Boniperti

                            case 2: price = 200; break;    //Sivori

                            case 3: price = 150; break;    //Regular
                            }
                        }
                    }
                    else
                    {
                        switch (ticket.CategoryId)
                        {
                        case 1: price = 250; break;    //Boniperti

                        case 2: price = 200; break;    //Sivori

                        case 3: price = 150; break;    //Regular
                        }
                    }

                    //string query = "Insert into dbo.Ticket_Game(TicketId, GameId, Price) values(" + ticket.Id + ", " + game.Id + ", " + price + ")";
                    //_context.Database.ExecuteSqlCommand(query);

                    Ticket_Game tg = new Ticket_Game(ticket.Id, game.Id, price);
                    _context.Ticket_Game.Add(tg);
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "Ticket"));
        }
Exemple #5
0
        public ActionResult Save(GameFormViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                //foreach (ModelState modelState in ViewData.ModelState.Values)
                //{
                //    foreach (ModelError error in modelState.Errors)
                //    {
                //        return Content(error.ErrorMessage);
                //    }
                //}
                var viewModel = new GameFormViewModel
                {
                    HomeTeam      = vm.HomeTeam,
                    AwayTeam      = vm.AwayTeam,
                    CompetitionId = vm.CompetitionId,
                    Date          = vm.Date,
                    Competitions  = _context.Ref_Competition.ToList()
                };
                return(View("Form", viewModel));
            }

            Dictionary <int, double> Prices = new Dictionary <int, double>();
            bool editMode = false;
            Game game     = null;

            if (vm.Id == 0)
            {
                game = new Game()
                {
                    Id            = vm.Id,
                    HomeTeam      = vm.HomeTeam,
                    AwayTeam      = vm.AwayTeam,
                    CompetitionId = vm.CompetitionId,
                    Date          = vm.Date,
                };
                _context.Games.Add(game);
            }
            else
            {
                editMode = true;
                var gameInDb = _context.Games.Single(c => c.Id == vm.Id);
                gameInDb.HomeTeam      = vm.HomeTeam;
                gameInDb.AwayTeam      = vm.AwayTeam;
                gameInDb.Date          = vm.Date;
                gameInDb.CompetitionId = vm.CompetitionId;
                game = gameInDb;
                string query         = "Select TicketId, Price From Ticket_Game Where Sold = 0 and GameId = " + gameInDb.Id + ";";
                var    ticket_prices = _context.Database.SqlQuery <TicketPricePair>(query).ToList();
                foreach (TicketPricePair tp in ticket_prices)
                {
                    Prices.Add(tp.TicketId, tp.Price);
                }
                //remove existing data
                //_context.Database.ExecuteSqlCommand("Delete from Ticket_Game Where Sold=0 and GameId = " + game.Id);
                var toRemove = _context.Ticket_Game.Where(m => m.GameId == vm.Id && m.Sold == 0);
                _context.Ticket_Game.RemoveRange(toRemove);
            }

            _context.SaveChanges();
            if (vm.SelectedTickets != null)
            {
                foreach (string s in vm.SelectedTickets)
                {
                    double price  = 0;
                    var    ticket = _context.Tickets.SingleOrDefault(m => m.Id.ToString() == s);
                    if (editMode)
                    {
                        if (Prices.ContainsKey(ticket.Id))
                        {
                            price = Prices[ticket.Id];
                        }
                        else
                        {
                            switch (ticket.CategoryId)
                            {
                            case 1: price = 250; break;    //Boniperti

                            case 2: price = 200; break;    //Sivori

                            case 3: price = 150; break;    //Regular
                            }
                        }
                    }
                    else
                    {
                        switch (ticket.CategoryId)
                        {
                        case 1: price = 250; break;    //Boniperti

                        case 2: price = 200; break;    //Sivori

                        case 3: price = 150; break;    //Regular
                        }
                    }

                    //string query = "Insert into dbo.Ticket_Game(TicketId, GameId, Price) values(" + ticket.Id + ", " + game.Id + ", " + price + ")";
                    //_context.Database.ExecuteSqlCommand(query);
                    Ticket_Game tg = new Ticket_Game(ticket.Id, game.Id, price);
                    _context.Ticket_Game.Add(tg);
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction("Index", "Game"));
        }