Exemplo n.º 1
0
        void TestProductsRepository()
        {
            var newproduct = new Products()
            {
                PartNbr  = "ZZZ", Name = "ZZZ",
                Price    = 10.99M, Unit = "Each", PhotoPath = null,
                VendorId = VendorsRepository.GetByPk(3).Id
            };

            if (!ProductsRepository.Insert(newproduct))
            {
                throw new Exception("Product insert failed!");
            }
            DisplayAllProducts();
            newproduct.Name = "YYY";
            if (!ProductsRepository.Update(newproduct))
            {
                throw new Exception("Product update failed!");
            }
            DisplayAllProducts();
            if (!ProductsRepository.Delete(newproduct))
            {
                throw new Exception("Product delete failed!");
            }
            DisplayAllProducts();
        }
Exemplo n.º 2
0
        public static void OrderProduct(User user)
        {
            Message.Print("To order a product, first type in the vendor name form the list:", ConsoleColor.DarkCyan);
            VendorsRepository.GetVendorsNames();
            string vendorName    = ReadLine();
            string vendorNameKey = VendorsRepository.VendorsAndProducts.Where(kvp => kvp.Key.ToLower().Contains(vendorName.ToLower())).FirstOrDefault().Key;

            if (!string.IsNullOrEmpty(vendorNameKey) && !string.IsNullOrEmpty(vendorName))
            {
                UserInputServices.GetVendorsProducts(vendorName);
            }
            else
            {
                Message.Print("Please try again and enter the vendor name correctly.", ConsoleColor.DarkRed);
                OrderProduct(user);
            }
            Message.Print("Now, type in the number of the product and its quantity, separated by a space:", ConsoleColor.DarkCyan);
            string[]       orderString     = ReadLine().Split();
            List <Product> vendorsProducts = UserInputServices.GetVendorsProductsAsList(vendorName);

            if (orderString.Length == 2 && Int32.TryParse(orderString[0], out int productNumber) && productNumber > 0 && productNumber <= vendorsProducts.Count && Int32.TryParse(orderString[1], out int productQuantity) && productQuantity > 0)
            {
                Product product = vendorsProducts[productNumber - 1];
                Order   order   = new Order(product.ProductName, productQuantity, product.ProductPrice);
                user.AddToShoppingCart(order);
                Message.Print($"Successfully created order for {productQuantity} {product.ProductName}((e)s), totaling {(productQuantity * product.ProductPrice).PrintFormattedMKDPrice()}", ConsoleColor.DarkGreen);
            }
            else
            {
                Message.Print("Please try again and correctly input the necessary information.", ConsoleColor.DarkRed);
            }
        }
Exemplo n.º 3
0
        void TestVendorsRepository()
        {
            var newvendor = new Vendors()
            {
                Code    = "ZZZ", Name = "ZZZ",
                Address = "123 Any St.", City = "Cincinnati", State = "OH", Zip = "54321",
                Phone   = null, Email = null
            };

            if (!VendorsRepository.Insert(newvendor))
            {
                throw new Exception("Vendor insert failed!");
            }
            DisplayAllVendors();
            newvendor.Name = "YYY";
            if (!VendorsRepository.Update(newvendor))
            {
                throw new Exception("Vendor update failed!");
            }
            DisplayAllVendors();
            if (!VendorsRepository.Delete(newvendor))
            {
                throw new Exception("Vendor delete failed!");
            }
            DisplayAllVendors();
        }
Exemplo n.º 4
0
        public HttpResponseMessage GetVendorsByType(string type)
        {
            var repository = new VendorsRepository();
            var result     = repository.ListAllVendors().Where(v => v.VendorTypeName == type);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 5
0
        public HttpResponseMessage GetSingleVendor(int id)
        {
            var repository = new VendorsRepository();
            var result     = repository.GetVendorById(id);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 6
0
        public HttpResponseMessage GetVendorsList()
        {
            var repository = new VendorsRepository();
            var result     = repository.ListAllVendors();

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemplo n.º 7
0
        public HttpResponseMessage EditVendor(int Id, VendorsDto vendor)
        {
            var repository = new VendorsRepository();
            var result     = repository.Edit(Id, vendor);

            if (result)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Vendor could not be updated"));
        }
Exemplo n.º 8
0
        public HttpResponseMessage AddNewVendor(VendorsDto vendor)
        {
            var repository = new VendorsRepository();
            var result     = repository.Create(vendor);

            if (result)
            {
                return(Request.CreateResponse(HttpStatusCode.Created));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Vendor could not be added"));
        }
Exemplo n.º 9
0
        public IHttpActionResult InsertVendorDetails([FromBody] Vendors vendor)
        {
            var vendorsRepo = new VendorsRepository();
            var result      = vendorsRepo.InsertVendorDetails(vendor);

            if (result <= 0)
            {
                return(Ok("Error occurred while inserting the New Vendor Details"));
            }
            return(Ok("New Vendor Details inserted"));
        }
Exemplo n.º 10
0
        public static void SearchProductCatalog()
        {
            VendorsRepository.GetAllProducts();
            Message.Print("This is the list of vendors, for your convenience:", ConsoleColor.Yellow);
            VendorsRepository.GetVendorsNames();
            WriteLine("In order to search the product catalog, please follow these instructions:\n\n- to search by vendor name input V and to search by product name input P,\n- then input the vendor name (just the first word of the name) or the product name or name of a part (just one word),\n- to view the products sorted by name input N or to view them sorted by price input P,\n- to view them in ascending order input A and to view them in descending order input D.\n\nExample search input:\n\nV bakery P A");
            Message.Print("Enter your input:", ConsoleColor.DarkCyan);
            string userSearchInput = ReadLine();

            string[] searchParameters = userSearchInput.Split(' ');
            if (searchParameters.Length == 4)
            {
                UserInputServices.GetProductsBySearchInput(searchParameters);
            }
            else
            {
                Message.Print("Please try again and input the information correctly.", ConsoleColor.DarkRed);
            }
        }
Exemplo n.º 11
0
 void DisplayAllVendors()
 {
     Console.WriteLine("\n*** Vendors ***");
     VendorsRepository.GetAll()
     .ForEach(v => { Console.WriteLine(v); });
 }
Exemplo n.º 12
0
        public static void EShopProgram(Dictionary <string, List <Product> > vendorsAndProducts, User user)
        {
            WriteLine(
                @"Choose what you want to do:

1. Get a list of all the vendors
2. Search the product catalog by vendor name or product name
3. Create an order for a product
4. View the products in the shopping cart
5. Remove an order for a product
6. Get an order receipt, proceed to payment and provide a shipping address
7. View your purchased orders
8. Exit the shop");

            string userInput = ReadLine();

            if (!Int32.TryParse(userInput, out int userInputNumber) || userInputNumber < 0 || userInputNumber > 9)
            {
                Message.Logo();
                Message.Print("Please try again and input a number between 1 and 8", ConsoleColor.DarkRed);
                EShopProgram(vendorsAndProducts, user);
            }
            else
            {
                Message.Logo();
                switch (userInputNumber)
                {
                case 1:
                    VendorsRepository.GetVendorsNames();
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 2:
                    UserInputServices.SearchProductCatalog();
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 3:
                    UserInputServices.OrderProduct(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 4:
                    UserInputServices.ViewProductsInCart(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 5:
                    UserInputServices.RemoveOrder(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 6:
                    if (user.GetShoppingCart().Count > 0)
                    {
                        user.PrintOrderReceipt();
                        WriteLine($"{Message.textDivider}\n");
                        UserInputServices.EnterShippingAddress(user);
                        UserInputServices.EnterPaymentMethod(user);
                    }
                    else
                    {
                        Message.Print("You have no products in your shopping cart yet.", ConsoleColor.Yellow);
                    }
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 7:
                    UserInputServices.GetOrdersByPrice(user);
                    EShopProgram(vendorsAndProducts, user);
                    break;

                case 8:
                    Message.Print($"Thank you for visiting our shop, {user.UserName}! Please visit us again.", ConsoleColor.DarkGreen);
                    Environment.Exit(0);
                    break;

                default:
                    Message.Logo();
                    Message.Print("Please try again and input a number between 1 and 8", ConsoleColor.DarkRed);
                    EShopProgram(vendorsAndProducts, user);
                    break;
                }
            }
        }