예제 #1
0
        public ActionResult UpdatePrices(int id)
        {
            var ticket = _context.Tickets.Single(c => c.Id == id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }
            var unsoldGames = ticket.GetAllUnsoldGames();

            foreach (Ticket_Game tg in unsoldGames)
            {
                var price = Request[tg.GameId.ToString()];
                if (price == "")
                {
                    price = "0";
                }
                double?     priceDouble = Convert.ToDouble(price);
                Ticket_Game toUpdate    = _context.Ticket_Game.Single(m => m.GameId == tg.GameId && m.TicketId == ticket.Id);
                toUpdate.Price = priceDouble;
                _context.SaveChanges();

                //string query = "UPDATE dbo.Ticket_Game SET Price = " + price + " WHERE TicketId = " + ticket.Id + " and GameId = " + tg.GameId + "; ";
                //_context.Database.ExecuteSqlCommand(query);
            }
            return(RedirectToAction("Index", "Ticket"));
        }
예제 #2
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"));
        }
예제 #3
0
 public int AddGame(Ticket_Game newGame)
 {
     _context.Ticket_Games.Add(newGame);
     _context.SaveChanges();
     UpdateTicket(new Ticket {
         Id = newGame.TicketId
     });
     return(1);
 }
예제 #4
0
        public void UpdateGame(Ticket_Game game)
        {
            var entity = _context.Ticket_Games
                         .FirstOrDefault(tg => tg.TicketId == game.TicketId && tg.GameId == game.GameId);

            if (entity != null)
            {
                entity.Type = game.Type;
            }
            _context.SaveChanges();
            UpdateTicket(new Ticket {
                Id = entity.TicketId
            });
        }
예제 #5
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();
        }
예제 #6
0
        public ActionResult Form()
        {
            List <Ticket_Game> selectedTickets = new List <Ticket_Game>();

            foreach (string name in Request.Form.AllKeys)
            {
                try
                {
                    int         n  = Convert.ToInt32(name);
                    Ticket_Game tg = _context.Ticket_Game.Single(m => m.Id == n);
                    // Ref 1
                    if (tg.Sold == 1)
                    {
                        //already sold
                        return(View("Error"));
                    }
                    selectedTickets.Add(tg);
                }
                catch (Exception e) {
                }
            }
            return(View(selectedTickets));
        }
예제 #7
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"));
        }
예제 #8
0
        public ActionResult ValidateCommand()
        {
            string tgs        = "";
            double?totalPrice = 0;
            string product;
            string game        = "";
            int    ticketCount = 0;

            // build tgId-tgName pairs
            foreach (string name in Request.Form.AllKeys)
            {
                try
                {
                    int         n  = Convert.ToInt32(name);
                    Ticket_Game tg = _context.Ticket_Game.Single(m => m.Id == n);
                    if (tg.Sold == 1)
                    {
                        //already sold
                        return(View("Error"));
                    }
                    totalPrice += tg.Price;
                    ticketCount++;
                    game = tg.Game.getFixture();
                    tgs += name + "-" + Request.Form[name] + ",";
                }
                catch (Exception e)
                {
                }
            }
            tgs     = tgs.TrimEnd(',');
            product = ticketCount + " ticket(s) " + game;
            PayPalModel paypal = new PayPalModel();

            paypal.cmd           = "_xclick";
            paypal.Tgs           = tgs;
            paypal.business      = "*****@*****.**";
            paypal.currency_code = "EUR";
            bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]);

            if (useSandbox)
            {
                ViewBag.actionUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            }
            else
            {
                ViewBag.actionUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            }
            paypal.cancel_return = ConfigurationManager.AppSettings["CancelUrl"];
            paypal.@return       = "https://localhost:44315/PayPal/RedirectFromPayPal?ids=" + paypal.id;
            paypal.notify_url    = "https://localhost:44315/PayPal/NotifyFromPaypal";



            paypal.item_name = product;
            paypal.amount    = totalPrice.ToString();
            Temp_PayPal tp = new Temp_PayPal
            {
                Id = paypal.id,
                Ticket_Game_Ids = paypal.Tgs
            };

            _context.Temp_PayPal.Add(tp);
            _context.SaveChanges();
            return(View(paypal));
        }
예제 #9
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"));
        }
예제 #10
0
 public IActionResult UpdateGame([FromBody] Ticket_Game game)
 {
     ticketProvider.UpdateGame(game);
     return(Ok());
 }
예제 #11
0
 public IActionResult Add([FromBody] Ticket_Game newGame)
 {
     ticketProvider.AddGame(newGame);
     return(Ok());
 }