Ejemplo n.º 1
0
 public Boolean UpdateClothingProduct(ClothingProduct product)
 {
     if (productGetway.UpdateProductInfo(product) > 0)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
 public JsonResult updateClothingProductInfo(ClothingProduct product)
 {
     if (productManager.UpdateClothingProduct(product))
     {
         return(Json("true", JsonRequestBehavior.AllowGet));
     }
     return(Json("false", JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 3
0
        public ActionResult ProductPage(String code, int sectionId, String name)
        {
            List <SectionC> sections = sectionManager.getAllSections();

            ViewBag.sections = sections;

            if (sectionId == 1)
            {
                ClothingProduct clothingProduct = productManager.getAClothingProduct(code)[0];
                ViewBag.product = clothingProduct;
            }
            else if (sectionId == 2)
            {
                ElectronicsProduct electronicsProduct = productManager.GetElectronicsProducts(code)[0];
                ViewBag.product = electronicsProduct;
            }
            else if (sectionId == 3)
            {
                DailyNeedProduct dailyNeedProduct = productManager.GetADailyNeedProuct(code)[0];
                ViewBag.product = dailyNeedProduct;
            }
            else if (sectionId == 4)
            {
                MobileProduct mobileProduct = productManager.GetAllMobileProduct(code)[0];
                ViewBag.product = mobileProduct;
            }
            else if (code.Equals("null") && sectionId == -1)
            {
                List <Product> products = productManager.GetProduct(name);

                int secId = products[0].SectionId;

                if (secId == 1)
                {
                    ClothingProduct clothingProduct = productManager.getAClothingProduct(products[0].ProductCode)[0];
                    ViewBag.product = clothingProduct;
                }
                else if (secId == 2)
                {
                    ElectronicsProduct electronicsProduct = productManager.GetElectronicsProducts(products[0].ProductCode)[0];
                    ViewBag.product = electronicsProduct;
                }
                else if (secId == 3)
                {
                    DailyNeedProduct dailyNeedProduct = productManager.GetADailyNeedProuct(products[0].ProductCode)[0];
                    ViewBag.product = dailyNeedProduct;
                }
                else if (secId == 4)
                {
                    MobileProduct mobileProduct = productManager.GetAllMobileProduct(products[0].ProductCode)[0];
                    ViewBag.product = mobileProduct;
                }
            }


            return(View());
        }
Ejemplo n.º 4
0
        public Boolean InsertClothingProduct(ClothingProduct product)
        {
            if (productGetway.insertClothingProduct(product) > 0)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public int insertClothingProduct(ClothingProduct product)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            String        Query      = "INSERT INTO products VALUES ('" + product.ProductName + "','" + product.ProductCode + "'," + product.SectionId + "," + product.Price + ",'" + product.Category + "','" + product.Description + "','" + product.ImageLink + "'," + product.LCount + "," + product.MCount + "," + product.XLCount + "," + product.XXLCount + ",null" + ",'" + product.BrandName + "')";
            SqlCommand    command    = new SqlCommand(Query, connection);

            connection.Open();
            int res = command.ExecuteNonQuery();

            connection.Close();

            return(res);
        }
Ejemplo n.º 6
0
        public int UpdateProductInfo(ClothingProduct product)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            String        Query      = "UPDATE products SET productName = '" + product.ProductName + "',ProductCode='" + product.ProductCode +
                                       "',Price=" + product.Price + ",Category ='" + product.Category + "',Description='" + product.Description + "',LCount=" + product.LCount + ",MCount=" +
                                       product.MCount + ",XLCount=" + product.XLCount + ",XXLCount=" + product.XXLCount + ",BrandName='" + product.BrandName + "' WHERE ProductId=" + product.ProductId;
            SqlCommand command = new SqlCommand(Query, connection);

            connection.Open();
            int res = command.ExecuteNonQuery();

            connection.Close();

            return(res);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add a clothing item product to the catalog
        /// </summary>
        /// <param name="newProduct">The new clothing product</param>
        /// <returns></returns>
        public async Task <IActionResult> AddClothing(ClothingProduct newProduct)
        {
            //Call API to add new product
            var response = await client.PostAsJsonAsync <ClothingProduct>("product/Clothing", newProduct);

            //check response for errors
            if (response.IsSuccessStatusCode)
            {
                var model = await response.Content.ReadAsAsync <ClothingProduct>();

                ViewData["ClothingModel"]   = model;
                ViewData["NewProductId"]    = model.Id;
                ViewData["ProgressMessage"] = "Product Created";
                return(View("Index"));
            }
            else
            {
                throw new ApplicationException(response.ReasonPhrase);
            }
        }
Ejemplo n.º 8
0
        public JsonResult getclothProduct(String Code)
        {
            ClothingProduct clothingProduct = productManager.getAClothingProduct(Code)[0];

            return(Json(clothingProduct, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        public void ShopMenuLogic(IShop shop, string option)
        {
            switch (option)
            {
            case "1":
                Console.Clear();
                try
                {
                    if (shop.GetProducts().Count > 0)
                    {
                        foreach (var product in shop.GetProducts())
                        {
                            Console.WriteLine($"Barcode: {product.GetBarcode()} Product name: {product} Available ammount: {shop.GetQuantityOf(product.GetBarcode())} Price: {shop.GetPrice(product.GetBarcode())} HUF");
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are not products yet!");
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("Please open the shop first!");
                }
                break;

            case "2":
                Console.Clear();
                Console.WriteLine("What product you are looking for?");
                var productName = Console.ReadLine();
                try
                {
                    Product currentProduct = shop.FindByName(productName);
                    Console.WriteLine($"Barcode: {currentProduct.GetBarcode()} Product name: {currentProduct} Available ammount: " +
                                      $"{shop.GetQuantityOf(currentProduct.GetBarcode())} Price: {shop.GetPrice(currentProduct.GetBarcode())} HUF");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("Please open the shop first!");
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no such product available.");
                }
                break;

            case "3":
                Console.Clear();
                Console.WriteLine(shop.GetOwner());
                break;

            case "4":
                Console.Clear();
                shop.Open();
                break;

            case "5":
                Console.Clear();
                shop.Close();
                break;

            case "6":
                Console.Clear();
                try
                {
                    Console.WriteLine("Press 1 if you want to add food, 2 for adding clothes");
                    var foodOrCloth = Console.ReadLine();
                    switch (foodOrCloth)
                    {
                    case "1":
                        Console.WriteLine("Pls give the barcode of the product");
                        var barcode = Console.ReadLine();
                        Console.WriteLine("What's the name of the product?");
                        var name = Console.ReadLine();
                        Console.WriteLine("Who is the manufacturer?");
                        var manufact = Console.ReadLine();
                        Console.WriteLine("How many calories it have?");
                        var calories = Console.ReadLine();
                        Console.WriteLine("Best before?");
                        var bestBefore   = Console.ReadLine();
                        var productToAdd = new FoodProduct(Convert.ToInt64(barcode), name, manufact, Convert.ToInt32(calories), Convert.ToDateTime(bestBefore));
                        Console.WriteLine("How many you want to add?");
                        var FoodQuantity = Console.ReadLine();
                        Console.WriteLine("How much it costs?");
                        var price = Console.ReadLine();
                        shop.AddNewProduct(productToAdd, Convert.ToInt32(FoodQuantity), Convert.ToSingle(price));
                        break;

                    case "2":
                        Console.WriteLine("Pls give the barcode of the product");
                        var barcodec = Console.ReadLine();
                        Console.WriteLine("What's the name of the product?");
                        var namec = Console.ReadLine();
                        Console.WriteLine("Who is the manufacturer?");
                        var manufactc = Console.ReadLine();
                        Console.WriteLine("What material it is");
                        var material = Console.ReadLine();
                        Console.WriteLine("What type is it?");
                        var type       = Console.ReadLine();
                        var clothToAdd = new ClothingProduct(Convert.ToInt64(barcodec), namec, manufactc, material, type);
                        Console.WriteLine("How many you want to add?");
                        var Clothesquanty = Console.ReadLine();
                        Console.WriteLine("How much it costs?");
                        var priceCloth = Console.ReadLine();
                        shop.AddNewProduct(clothToAdd, Convert.ToInt32(Clothesquanty), Convert.ToSingle(priceCloth));
                        break;

                    default:
                        Console.WriteLine("Invalid input");
                        break;
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid Input format.");
                }
                catch (ProductAlreadyExistsException)
                {
                    Console.WriteLine("The given product already exists");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("Please open the shop first!");
                }
                break;

            case "7":
                Console.Clear();
                try
                {
                    Console.Clear();
                    Console.WriteLine("Pls give the barcode of the product");
                    var barcodeToAdd = Console.ReadLine();
                    Console.WriteLine("Pls give quantity you want to add.");
                    var quantity = Console.ReadLine();
                    shop.AddProduct(Convert.ToInt64(barcodeToAdd), Convert.ToInt32(quantity));
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid Input format.");
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product like that available!");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("Please open the shop first!");
                }
                break;

            case "8":
                Console.Clear();
                try
                {
                    Console.WriteLine("Please enter the barcode of the product you want to buy");
                    var barcodeToBuy = Convert.ToInt64(Console.ReadLine());
                    Console.WriteLine("How many products you wanna buy?");
                    var quant = Convert.ToInt32(Console.ReadLine());
                    if (quant == 1)
                    {
                        Cart.Add(shop.BuyProduct(barcodeToBuy));
                        Prices.Add(shop.GetPrice(barcodeToBuy));
                    }
                    else if (quant > 1)
                    {
                        Cart.AddRange(shop.BuyProducts(barcodeToBuy, quant));
                        for (int i = 0; i < quant; i++)
                        {
                            Prices.Add(shop.GetPrice(barcodeToBuy));
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid input");
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid Input format.");
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product like that available!");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("Please open the shop first!");
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("We don't have enough supply! :(");
                }
                break;

            case "9":
                Console.Clear();
                try
                {
                    Console.WriteLine("Please enter the barcode of the product you want to check");
                    var barcodeToCheck = Convert.ToInt64(Console.ReadLine());
                    Console.WriteLine($"The price of {shop.GetProductName(barcodeToCheck)}: {shop.GetPrice(barcodeToCheck)} HUF");
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid Input format.");
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product like that available!");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("Please open the shop first!");
                }
                break;

            case "0":
                inAShop = false;
                break;

            default:
                Console.WriteLine("Invalid input");
                Thread.Sleep(500);
                Console.Clear();
                break;
            }
        }
Ejemplo n.º 10
0
        public ActionResult AddProduct(ClothingProduct product, ElectronicsProduct electronics, DailyNeedProduct dailyNeeds, MobileProduct mobile, int SectionId)
        {
            WebImage photo       = null;
            var      newFileName = "";
            var      imagePath   = "";

            photo = WebImage.GetImageFromRequest();
            if (product.ProductName != null && product.SectionId > 0 && product.ProductCode != null && product.Price != 0 && photo != null)
            {
                if (!productManager.isThisCodeAlreadyExist(product.ProductCode))
                {
                    photo.FileName = product.ProductCode + "img";
                    newFileName    = photo.FileName;


                    imagePath = @"Style/ProductImage/" + product.SectionId + @"/" + newFileName;

                    photo.Save(@"~/" + imagePath);
                    Boolean res = false;
                    if (SectionId == 1)
                    {
                        product.ImageLink = imagePath;
                        res = productManager.InsertClothingProduct(product);
                    }

                    else if (SectionId == 2)
                    {
                        electronics.ImageLink = imagePath;
                        res = productManager.InsertElectronicsProduct(electronics);
                    }

                    else if (SectionId == 3)
                    {
                        dailyNeeds.ImageLink = imagePath;
                        res = productManager.InsertDailyNeedsProduct(dailyNeeds);
                    }

                    else if (SectionId == 4)
                    {
                        mobile.ImageLink = imagePath;
                        productManager.InsertMobileProduct(mobile);
                    }

                    if (res)
                    {
                        ViewBag.insertResult = "1";

                        List <ClothingProduct>    clothingProducts    = productManager.GetAllCLothingProduct();
                        List <ElectronicsProduct> electronicsProducts = productManager.GetAllElectroinicProduct();
                        List <DailyNeedProduct>   dailyNeedProducts   = productManager.GetADailyNeedProuct();
                        List <MobileProduct>      mobileProducts      = productManager.GetAllMobileProduct();
                        return(View(new AdminSectionC((AdminC)Session["adminIndo"], (List <SectionC>)Session["sectionInfo"], clothingProducts, electronicsProducts, dailyNeedProducts, mobileProducts)));
                    }
                    else
                    {
                        List <ClothingProduct>    clothingProducts    = productManager.GetAllCLothingProduct();
                        List <ElectronicsProduct> electronicsProducts = productManager.GetAllElectroinicProduct();
                        List <DailyNeedProduct>   dailyNeedProducts   = productManager.GetADailyNeedProuct();
                        List <MobileProduct>      mobileProducts      = productManager.GetAllMobileProduct();
                        return(View(new AdminSectionC((AdminC)Session["adminIndo"], (List <SectionC>)Session["sectionInfo"], clothingProducts, electronicsProducts, dailyNeedProducts, mobileProducts)));
                    }
                }
                else
                {
                    ViewBag.insertResult = "2";
                    List <ClothingProduct>    clothingProducts    = productManager.GetAllCLothingProduct();
                    List <ElectronicsProduct> electronicsProducts = productManager.GetAllElectroinicProduct();
                    List <DailyNeedProduct>   dailyNeedProducts   = productManager.GetADailyNeedProuct();
                    List <MobileProduct>      mobileProducts      = productManager.GetAllMobileProduct();
                    return(View(new AdminSectionC((AdminC)Session["adminIndo"], (List <SectionC>)Session["sectionInfo"], clothingProducts, electronicsProducts, dailyNeedProducts, mobileProducts)));
                }
            }
            else
            {
                ViewBag.insertResult = "3";
                List <ClothingProduct>    clothingProducts    = productManager.GetAllCLothingProduct();
                List <ElectronicsProduct> electronicsProducts = productManager.GetAllElectroinicProduct();
                List <DailyNeedProduct>   dailyNeedProducts   = productManager.GetADailyNeedProuct();
                List <MobileProduct>      mobileProducts      = productManager.GetAllMobileProduct();
                return(View(new AdminSectionC((AdminC)Session["adminIndo"], (List <SectionC>)Session["sectionInfo"], clothingProducts, electronicsProducts, dailyNeedProducts, mobileProducts)));
            }
        }
Ejemplo n.º 11
0
        public async Task <JsonResult> AddClothing(ClothingProduct product)
        {
            var newProduct = await docService.AddProductAsync <ClothingProduct>(product);

            return(new JsonResult(newProduct));
        }
Ejemplo n.º 12
0
        bool ChooseShop(Shop shop)
        {
            string choice = AnyInput("Please choose an option...");

            switch (choice)
            {
            case "1":     // is the shop open?
                Console.Clear();
                if (shop.IsOpen())
                {
                    Console.WriteLine("The shop is opened.");
                }
                else
                {
                    Console.WriteLine("The shop is closed.");
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "2":     // open shop
                Console.Clear();
                shop.Open();
                Console.WriteLine("The shop has just opened.");
                Thread.Sleep(1000);
                return(true);

            case "3":     // close shop
                Console.Clear();
                shop.Close();
                Console.WriteLine("The shop has just closed.");
                Thread.Sleep(1000);
                return(true);

            case "4":     // list the products
                Console.Clear();
                Dictionary <long, int>     quanityOfProduct   = new Dictionary <long, int>();
                Dictionary <long, Product> ProductsDictionary = new Dictionary <long, Product>();
                try
                {
                    foreach (Product product in shop.GetProducts())
                    {
                        long barcode = product.GetBarcode();
                        if (quanityOfProduct.ContainsKey(barcode))
                        {
                            quanityOfProduct[barcode] += +1;
                        }
                        else
                        {
                            quanityOfProduct.Add(barcode, 1);
                            ProductsDictionary.Add(barcode, product);
                        }
                    }
                    foreach (KeyValuePair <long, int> item in quanityOfProduct)
                    {
                        Product product = ProductsDictionary[item.Key];
                        Console.Write(product.ToString());
                        Console.WriteLine(", Quantity: " + item.Value);
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed.");
                    Thread.Sleep(1000);
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "5":     // find a product by name
                Console.Clear();
                try
                {
                    string  productName = AnyInput("The name of the product: ");
                    Product product     = shop.FindByName(productName);
                    Console.WriteLine(product.ToString());
                    AnyInput("Press any key to continue...");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed.");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no such product with this name.");
                    Thread.Sleep(1000);
                }
                return(true);

            case "6":     // get the owner of the shop
                Console.Clear();
                Console.WriteLine(shop.GetOwner());
                AnyInput("Press any key to continue...");
                return(true);

            case "7":     // add new product
                try
                {
                    Console.Clear();
                    Console.WriteLine("(1) Add a new foodproduct");
                    Console.WriteLine("(2) Add a new clothing product");
                    while (true)
                    {
                        if (!shop.IsOpen())
                        {
                            throw new ShopIsClosedException();
                        }
                        int    input        = IntInput("Choose an option...");
                        long   barcode      = LongInput("The barcode of the product: ");
                        string name         = AnyInput("The name of the product: ");
                        string manufacturer = AnyInput("The manufacturer of the product: ");
                        if (input == 1)
                        {
                            int         calories    = IntInput("The calorie of the product: ");
                            DateTime    bestBefore  = DateTimeInput("The expiration date of the product: ");
                            FoodProduct foodProduct = new FoodProduct(barcode, name, manufacturer, calories, bestBefore);
                            int         quantity    = IntInput("The quantity of the product: ");
                            int         price       = IntInput("The price of the product: ");
                            shop.AddNewProduct(foodProduct, quantity, price);
                            Console.WriteLine("The new product has added to the shop.");
                            Thread.Sleep(1000);
                            break;
                        }
                        else if (input == 2)
                        {
                            string          material        = AnyInput("The material of the product: ");
                            string          type            = AnyInput("The type of the product: ");
                            ClothingProduct clothingProduct = new ClothingProduct(barcode, name, manufacturer, material, type);
                            int             quantity        = IntInput("The quantity of the product: ");
                            int             price           = IntInput("The price of the product: ");
                            shop.AddNewProduct(clothingProduct, quantity, price);
                            Console.WriteLine("The new product has added to the shop.");
                            Thread.Sleep(1000);
                            break;
                        }
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (ProductAlreadyExistsException)
                {
                    Console.WriteLine("The product is already exist");
                    Thread.Sleep(1000);
                }
                return(true);

            case "8":     // add existing product
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long barcode  = LongInput("The barcode of the product: ");
                    int  quantity = IntInput("The quantity: ");
                    shop.AddProduct(barcode, quantity);
                    Console.WriteLine("The product is added to the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                return(true);

            case "9":     //Buy a product
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long    barcode       = LongInput("The barcode of the product: ");
                    Product boughtProduct = shop.BuyProduct(barcode);
                    cart.Add(boughtProduct);
                    prices.Add(shop.GetPrice(boughtProduct.GetBarcode()));
                    Console.WriteLine("The product is bought from the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has run out of this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "10":     // Buy products
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long           barcode        = LongInput("The barcode of the product: ");
                    int            quantity       = IntInput("The quantity: ");
                    List <Product> boughtProducts = shop.BuyProducts(barcode, quantity);
                    foreach (Product product in boughtProducts)
                    {
                        cart.Add(product);
                        prices.Add(shop.GetPrice(product.GetBarcode()));
                    }
                    Console.WriteLine("The products are bought from the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has not enough from this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "11":     // Get the price
                Console.Clear();
                try
                {
                    long barcode = LongInput("The barcode of the product: ");
                    Console.WriteLine("The price is: " + shop.GetPrice(barcode).ToString());
                    AnyInput("Press any key to continue...");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has not enough from this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "0":
                return(false);

            default:
                return(true);
            }
        }