コード例 #1
0
        public JsonResult Index(OrderViewModel objOrderViewModel)
        {
            OrderRepo objOrderRepo = new OrderRepo();

            objOrderRepo.AddOrder(objOrderViewModel);
            return(Json(data: "order thành công :>", JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult OrderProduct(int id)
        {
            CartRepo  cr1   = new CartRepo();
            CartModel cart2 = cr1.GetCart(id);

            int    pId   = (int)cart2.ProductID;
            int    q     = (int)cart2.Quantity;
            int    c     = (int)cart2.CustomerID;
            int    tp    = (int)cart2.TotalPrice;
            String pname = cart2.Product.ProductName;

            //orderModel = new OrderModel(15001, c, pId, pname, q, tp, null);
            orderModel = new OrderModel()
            {
                OrderID     = 15001,
                CustomerID  = c,
                ProductID   = pId,
                ProductName = pname,
                Quantity    = q,
                TotalPrice  = tp,
                OrderDate   = null
            };

            Boolean b = op.AddOrder(orderModel);

            if (b == true)
            {
                cr1.DeleteProduct(cart2.CartID);

                pr = new ProductRepo();
                pr.EditProductQuantity(pId, q);
            }

            return(RedirectToAction("ShowOrders"));
        }
コード例 #3
0
        public JsonResult Index(OrderViewModel orderViewModel)
        {
            OrderRepo orderRepo = new OrderRepo();

            orderRepo.AddOrder(orderViewModel);
            return(Json("Order placed! Total: " + orderViewModel.FinalTotal.ToString(), JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public OrderModel CalculateOrder(int customerId, List <int> productIDs)
        {
            var customerRepo = new CustomerRepo(_connString);
            var productRepo  = new ProductRepo(_connString);

            var customerInfo = customerRepo.GetCustomerById(customerId).CTM();
            var productInfo  = productRepo.GetProductsByIDs(productIDs).CTMs();

            var order     = CalculateOrder(productInfo, customerInfo.Discounts, customerInfo.Address, customerId, _fedExLicense);
            var orderRepo = new OrderRepo(_connString);

            order.Status  = Order.Enums.OrderStatus.Calculated;
            order.OrderId = orderRepo.AddOrder(order.CTE());
            return(order);
        }
コード例 #5
0
        public OrderModel CalculateOrder(int customerId, List <int> productIDs)
        {
            //                                   vvvvvvvvvvvvvvvvvvvvvvvvv
            var customerRepo = new CustomerRepo("sql:username:password:etc");
            var productRepo  = new ProductRepo("sql:username:password:etc");

            var customerInfo = customerRepo.GetCustomerById(customerId).CTM();
            var productInfo  = productRepo.GetProductsByIDs(productIDs).CTMs();

            var order     = CalculateOrder(productInfo, customerInfo.Discounts, customerInfo.Address, customerId);
            var orderRepo = new OrderRepo("sql:username:password:etc");

            order.Status  = Order.Enums.OrderStatus.Calculated;
            order.OrderId = orderRepo.AddOrder(order.CTE());
            return(order);
        }
コード例 #6
0
        //Möguleg föll sem við munum útfæra:
        //AddOrder()
        //EditOrder()
        //GetOrders()
        //GetOrder()
        //RemoveOrder()

        public void AddOrder(OrderInputModel model)
        {
            DateTime  today       = DateTime.Today;
            DateModel dateOrdered = new DateModel()
            {
                Year  = today.Year,
                Month = today.Month,
                Day   = today.Day
            };
            double totalPrice = 0;

            for (int i = 0; i < model.Books.Count; i++)
            {
                totalPrice += (model.Books[i].Price * model.Books[i].Amount);
            }
            _orderRepo.AddOrder(model, totalPrice, dateOrdered);
        }
コード例 #7
0
        public void AddAnOrder()
        {
            Order newOrder = new Order();

            Console.WriteLine("Please enter the customer's name");
            newOrder.CustomerName = Console.ReadLine().Trim();

            Console.WriteLine("Please enter product type number:\n" +
                              "1. Bread\n" +
                              "2. Cake\n" +
                              "3. Pastry\n" +
                              "4. Pie");
            string userInput = Console.ReadLine();

            userInput = userInput.Replace(" ", "");
            userInput = userInput.Trim();

            switch (userInput)
            {
            case "1":
                newOrder.Product = _products[0];
                break;

            case "2":
                newOrder.Product = _products[1];
                break;

            case "3":
                newOrder.Product = _products[2];
                break;

            case "4":
                newOrder.Product = _products[3];
                break;
            }

            Console.WriteLine("Please enter the quantity of the product you'd like to order");
            string quantityString = Console.ReadLine();

            newOrder.ProductQuantity = Convert.ToInt32(quantityString);

            _orderRepo.AddOrder(newOrder);
        }
コード例 #8
0
 public async Task AddOrder(PaymentVM pvm)
 {
     await _repo.AddOrder(pvm);
 }
コード例 #9
0
        static void Main(string[] args)
        {
            logger.Info("Beginning data retrieval");

            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = configBuilder.Build();

            var optionsBuilder = new DbContextOptionsBuilder <Project1PizzaApplicationContext>();

            optionsBuilder.UseSqlServer(configuration.GetConnectionString("Project1PizzaApplication"));

            logger.Info("Creating repo objects");
            var userRepo     = new UserRepo(new Project1PizzaApplicationContext(optionsBuilder.Options));
            var locationRepo = new LocationRepo(new Project1PizzaApplicationContext(optionsBuilder.Options));
            var orderRepo    = new OrderRepo(new Project1PizzaApplicationContext(optionsBuilder.Options));

            logger.Info("Repo objects created");

            logger.Info("Beginning application");
            User     CurrentUser = new User();
            Location Reston      = new Location("Reston");
            Location Herndon     = new Location("Herndon");
            Location Dulles      = new Location("Dulles");
            Location Hattontown  = new Location("Hattontown");
            int      NumPizzas;

            logger.Info("Obtaining information from database");
            var UserList     = userRepo.GetUsers();
            var LocationList = locationRepo.GetLocations();
            var OrderList    = orderRepo.GetOrders();

            logger.Info("Information obtained");

            logger.Info("Setting location information");
            foreach (var item in LocationList)
            {
                if (item.CityName.ToLower() == "reston")
                {
                    Reston = Mapper.Map(item);
                }
                if (item.CityName.ToLower() == "herndon")
                {
                    Herndon = Mapper.Map(item);
                }
                if (item.CityName.ToLower() == "hattontown")
                {
                    Hattontown = Mapper.Map(item);
                }
                if (item.CityName.ToLower() == "dulles")
                {
                    Dulles = Mapper.Map(item);
                }
            }

            logger.Info("Setting location order history");
            foreach (var item in OrderList)
            {
                if (item.StoreLocation.ToLower() == "reston")
                {
                    Reston.OrderHistory.Add(Mapper.Map(item));
                }
                if (item.StoreLocation.ToLower() == "herndon")
                {
                    Herndon.OrderHistory.Add(Mapper.Map(item));
                }
                if (item.StoreLocation.ToLower() == "hattontown")
                {
                    Hattontown.OrderHistory.Add(Mapper.Map(item));
                }
                if (item.StoreLocation.ToLower() == "dulles")
                {
                    Dulles.OrderHistory.Add(Mapper.Map(item));
                }
            }
            logger.Info("All information obtained and set");

            Console.WriteLine("Welcome to our new pizza application!");
            string Input;
            bool   UsernameEntered = false;

            while (!UsernameEntered)
            {
                Console.WriteLine("Please enter a valid username, type 'users' to see all current users, or enter 'new'");
                logger.Info("Obtaining username");
                Input = Console.ReadLine();
                Input = Input.ToLower();
                if (Input.Equals("new"))
                {
                    logger.Info("Creating New User");
                    CurrentUser = CreateNewUser(UserList, userRepo);
                    logger.Info("New User Created");
                    UsernameEntered = true;
                    Console.Clear();
                }
                else if (UserList.Any(u => u.Username.ToLower() == Input))
                {
                    logger.Info("Retrieving user information");
                    foreach (var item in UserList)
                    {
                        if (item.Username.ToLower() == Input)
                        {
                            CurrentUser = Mapper.Map(item);
                        }
                    }
                    logger.Info("User information retrieved");
                    UsernameEntered = true;
                    Console.Clear();
                }
                else if (Input.Equals("users"))
                {
                    logger.Info("Listing current users");
                    ViewCurrentUsers(UserList);
                    logger.Info("Users listed");
                }
                else
                {
                    Console.WriteLine("Username not detected.");
                }
            }

            bool KeepOpen = true;

            while (KeepOpen)
            {
                Console.WriteLine("Welcome! Let's get started!");
                Console.WriteLine("Please input one of the following:");
                Console.WriteLine("Order: place a new order; History: view your order history; Exit: exit the application");
                logger.Info("Recieving use input");
                Input = Console.ReadLine();
                Input = Input.ToLower();

                if (!Input.Equals("order") && !Input.Equals("exit") && !Input.Equals("history") && !Input.Equals("resupply"))
                {
                    Console.WriteLine("Please input an accepted command");
                    Console.WriteLine("Order: place a new order; History : view your order history; Exit: exit the application");
                    Input = Console.ReadLine();
                    Input = Input.ToLower();
                }
                else if (Input.Equals("order"))
                {
                    logger.Info("Order selected");
                    Console.Clear();
                    Console.WriteLine("How many pizzas would you like to order (max of 12)? Please input a number.");
                    Input = Console.ReadLine();
                    try
                    {
                        NumPizzas = int.Parse(Input);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: Input was not an integer. Please input a number.");
                        continue;
                    }

                    if (NumPizzas < 0)
                    {
                        Console.WriteLine("Error: Invalid input detected (we can't make negative pizzas)");
                        Console.WriteLine("Let's try this again from the top.");
                    }
                    else if (NumPizzas == 0)
                    {
                        Console.WriteLine("Wait...didn't you want to order at least one pizza? We have to start over...");
                    }
                    else if (NumPizzas > 0 && NumPizzas <= 12)
                    {
                        logger.Info("Beginning order creation");
                        Console.WriteLine("Are we delivering from your favorite store? Y/N");
                        Console.WriteLine("Your favorite store is: " + CurrentUser.Favorite);
                        Input = Console.ReadLine().ToLower();
                        bool   ValidLocation    = false;
                        bool   AcceptedInput    = false;
                        string DeliveryLocation = "";
                        if (Input != "y" && Input != "n")
                        {
                            while (!AcceptedInput)
                            {
                                Console.WriteLine("Please input either 'y' for yes or 'n' for no.");
                                Input = Console.ReadLine().ToLower();
                                if (Input == "y" && Input == "n")
                                {
                                    AcceptedInput = true;
                                }
                            }
                        }
                        if (Input == "n")
                        {
                            while (!ValidLocation)
                            {
                                Console.WriteLine("Which location shall we send the order to?");
                                Console.WriteLine("Valid locations: Reston, Herndon, Dulles, Hattontown");
                                DeliveryLocation = Console.ReadLine().ToLower();
                                if (DeliveryLocation != "reston" && DeliveryLocation != "herndon" && DeliveryLocation != "dulles" && DeliveryLocation != "hattontown")
                                {
                                    Console.WriteLine("Please input a valid location.");
                                }
                                else
                                {
                                    ValidLocation = true;
                                }
                            }
                        }
                        if (Input == "y")
                        {
                            DeliveryLocation = CurrentUser.Favorite;
                            DeliveryLocation.ToLower();
                        }

                        Order CurrentOrder = new Order();
                        bool  CanOrder     = true;
                        logger.Info("Checking if user ordered more than 2 hours ago");
                        switch (DeliveryLocation)
                        {
                        case "reston":
                            CanOrder = Reston.LastOrderOverTwoHoursAgo(CurrentUser);

                            if (CanOrder)
                            {
                                CurrentOrder = Reston.CreateOrder(CurrentUser, NumPizzas);
                            }
                            break;

                        case "herndon":
                            CanOrder = Herndon.LastOrderOverTwoHoursAgo(CurrentUser);

                            if (CanOrder)
                            {
                                CurrentOrder = Herndon.CreateOrder(CurrentUser, NumPizzas);
                            }
                            break;

                        case "dulles":
                            CanOrder = Dulles.LastOrderOverTwoHoursAgo(CurrentUser);

                            if (CanOrder)
                            {
                                CurrentOrder = Dulles.CreateOrder(CurrentUser, NumPizzas);
                            }
                            break;

                        case "hattontown":
                            CanOrder = Hattontown.LastOrderOverTwoHoursAgo(CurrentUser);

                            if (CanOrder)
                            {
                                CurrentOrder = Hattontown.CreateOrder(CurrentUser, NumPizzas);
                            }
                            break;

                        default:
                            break;
                        }
                        logger.Info("Check complete");
                        if (CanOrder)
                        {
                            logger.Info("Creating order");
                            CurrentUser.UserFavoritePizza(CurrentOrder);
                            orderRepo.AddOrder(CurrentOrder);

                            Console.Clear();
                            Console.WriteLine("Your order has been placed!");
                            Console.WriteLine("");
                            logger.Info("Order placed");
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("We're sorry, but you have already placed an order at this location within the past two hours.");
                            Console.WriteLine("Please begin the order again selecting another location or wait two hours");
                            Console.WriteLine("");
                            logger.Info("User unable to order from chosen location");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error: There is a 12 pizza maximum. Please input a lower number of pizzas.");
                        Console.WriteLine("We're going to have to start over...");
                        logger.Info("User attempted to go over pizza limit");
                    }
                }
                else if (Input.Equals("history"))
                {
                    Console.Clear();
                    Console.WriteLine("How would you like the information displayed?");
                    Console.WriteLine("We can sort by: earliest, latest, cheapest, most expensive.");
                    Console.WriteLine("Type '1' for earliest, '2' for latest, '3' for cheapest, or '4' for most expensive.");
                    string Sort = Console.ReadLine();
                    Console.WriteLine("");

                    logger.Info("Displaying order history for user");
                    List <Order> UserOrderHistory = new List <Order>();
                    dynamic      SortedHistory    = "";
                    UserOrderHistory.AddRange(DisplayUserOrderHistory(CurrentUser, Sort, Reston));
                    UserOrderHistory.AddRange(DisplayUserOrderHistory(CurrentUser, Sort, Herndon));
                    UserOrderHistory.AddRange(DisplayUserOrderHistory(CurrentUser, Sort, Dulles));
                    UserOrderHistory.AddRange(DisplayUserOrderHistory(CurrentUser, Sort, Hattontown));

                    switch (Sort)
                    {
                    case "1":
                        SortedHistory = UserOrderHistory.OrderBy(x => x.OrderPlaced).Select(x => x);
                        break;

                    case "2":
                        SortedHistory = UserOrderHistory.OrderByDescending(x => x.OrderPlaced).Select(x => x);
                        break;

                    case "3":
                        SortedHistory = UserOrderHistory.OrderBy(x => x.cost);
                        break;

                    case "4":
                        SortedHistory = UserOrderHistory.OrderByDescending(x => x.cost);
                        break;

                    default:
                        break;
                    }

                    foreach (var item in SortedHistory)
                    {
                        Console.WriteLine(item.OrderPlaced + " Total cost: $" + item.cost + ".00  Total pizzas:" + item.NumberOfPizzas +
                                          " from our " + item.location + " location.");
                        Console.WriteLine("You ordered:");
                        Console.WriteLine("");
                        for (int i = 0; i < item.NumberOfPizzas; i++)
                        {
                            Console.WriteLine("     " + item.PrintPizza(item.DesiredSizes[i], item.DesiredTypes[i]));
                        }
                        Console.WriteLine("");
                    }
                    logger.Info("History displayed");
                }

                else if (Input.Equals("resupply"))
                {
                    logger.Info("Resupplying location");
                    Console.Clear();
                    Console.WriteLine("Which store shall we resupply?");
                    Console.WriteLine("Enter 'Reston', 'Herndon', 'Dulles', or 'Hattontown'.");
                    string ResupplyLoc = Console.ReadLine().ToLower();

                    switch (ResupplyLoc)
                    {
                    case "reston":
                        Reston.Resupply();
                        break;

                    case "herndon":
                        Herndon.Resupply();
                        break;

                    case "dulles":
                        Dulles.Resupply();
                        break;

                    case "hattontown":
                        Hattontown.Resupply();
                        break;

                    default:
                        break;
                    }
                }

                else if (Input.Equals("exit"))
                {
                    KeepOpen = false;
                }
            }

            logger.Info("Updating user favorite pizza");
            foreach (var item in UserList)
            {
                if (item.Username == CurrentUser.Username)
                {
                    item.RecommendedPizza    = CurrentUser.FavoritePizza;
                    item.NumCheeseOrdered    = CurrentUser.CheeseOrdered;
                    item.NumPepperoniOrdered = CurrentUser.PepperoniOrdered;
                    item.NumMeatOrdered      = CurrentUser.MeatOrdered;
                    item.NumVeggieOrdered    = CurrentUser.VeggieOrdered;
                    userRepo.UpdateUser(item);
                }
            }
            logger.Info("Update complete");

            logger.Info("Updating location inventories");
            foreach (var item in LocationList)
            {
                if (item.CityName.ToLower() == "reston")
                {
                    item.DoughRemaining     = Reston.Dough;
                    item.SauceRemaining     = Reston.Sauce;
                    item.CheeseRemaining    = Reston.Cheese;
                    item.PepperoniRemaining = Reston.Pepperoni;
                    item.MeatRemaining      = Reston.HamAndMeatball;
                    item.VeggiesRemaining   = Reston.PeppersAndOnions;
                    locationRepo.EditLocation(item);
                }
                if (item.CityName.ToLower() == "herndon")
                {
                    item.DoughRemaining     = Herndon.Dough;
                    item.SauceRemaining     = Herndon.Sauce;
                    item.CheeseRemaining    = Herndon.Cheese;
                    item.PepperoniRemaining = Herndon.Pepperoni;
                    item.MeatRemaining      = Herndon.HamAndMeatball;
                    item.VeggiesRemaining   = Herndon.PeppersAndOnions;
                    locationRepo.EditLocation(item);
                }
                if (item.CityName.ToLower() == "hattontown")
                {
                    item.DoughRemaining     = Hattontown.Dough;
                    item.SauceRemaining     = Hattontown.Sauce;
                    item.CheeseRemaining    = Hattontown.Cheese;
                    item.PepperoniRemaining = Hattontown.Pepperoni;
                    item.MeatRemaining      = Hattontown.HamAndMeatball;
                    item.VeggiesRemaining   = Hattontown.PeppersAndOnions;
                    locationRepo.EditLocation(item);
                }
                if (item.CityName.ToLower() == "dulles")
                {
                    item.DoughRemaining     = Dulles.Dough;
                    item.SauceRemaining     = Dulles.Sauce;
                    item.CheeseRemaining    = Dulles.Cheese;
                    item.PepperoniRemaining = Dulles.Pepperoni;
                    item.MeatRemaining      = Dulles.HamAndMeatball;
                    item.VeggiesRemaining   = Dulles.PeppersAndOnions;
                    locationRepo.EditLocation(item);
                }
            }
            logger.Info("update complete, closing application");

            Environment.Exit(0);
        }