protected void btnAdd_Click(object sender, ImageClickEventArgs e)
    {

        if (!ucSelectProduct.Name.Contains("|"))
        {
            ShowError("O produto integrante da composição deve ter embalagem para aparecer na lista.");
            return;
        }


        if (ucSelectProduct.Package == null)
        {
            ShowError("O produto integrante da composição deve ter embalagem para aparecer na lista.");
            return;
        }

        //
        // Populate the entity CompositeProduct to be inserted 
        //
        var compositeProduct = new CompositeProduct
                               {
                                   Amount = Convert.ToInt32(ucCurrFieldQuantity.Text),
                                   CompositeProductId = productId,
                                   ProductManufacturerId = ucSelectProduct.Manufacturer.ProductManufacturerId,
                                   ProductPackageId = ucSelectProduct.Package.ProductPackageId,
                                   ProductId = ucSelectProduct.Product.ProductId
                               };

        new ProductManager(this).AddComposite(compositeProduct);
        grdComposites.DataBind();
        ucSelectProduct.Name = String.Empty;
        ucCurrFieldQuantity.CurrencyValue = null;
    }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("CompositeProductID,DateCreated,ProductTypeID,InkID,ScreenID,OrderID")] CompositeProduct compositeProduct)
        {
            if (id != compositeProduct.CompositeProductID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(compositeProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompositeProductExists(compositeProduct.CompositeProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["InkID"]         = new SelectList(_context.Ink, "InkID", "InkID", compositeProduct.InkID);
            ViewData["OrderID"]       = new SelectList(_context.Order, "OrderID", "UserId", compositeProduct.OrderID);
            ViewData["ProductTypeID"] = new SelectList(_context.ProductType, "ProductTypeID", "BaseColor", compositeProduct.ProductTypeID);
            ViewData["ScreenID"]      = new SelectList(_context.Screen, "ScreenID", "Title", compositeProduct.ScreenID);
            return(View(compositeProduct));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CompositeProduct> > GetProduct(string slug)
        {
            var product = await _productRepository.GetOne(slug);

            var reviewsTask         = Task.Run(() => _reviewService.GetReviews(product.Id));
            var relatedProductsTask = Task.Run(() => _relatedProductService.GetRelatedProducts(product.Id));
            var inventoryTask       = Task.Run(() => _inventoryService.GetInventoryForProduct(product.Id));

            await Task.WhenAll(reviewsTask, relatedProductsTask, inventoryTask);

            var reviews         = await reviewsTask;
            var relatedProducts = await relatedProductsTask;
            var inventory       = await inventoryTask;

            var CompositeProduct = new CompositeProduct
            {
                ProductDetails = product,
                Reviews        = reviews,
                Inventory      = inventory
            };

            var relatedProductsList = new List <ProductTransferObject>();

            foreach (var entry in relatedProducts)
            {
                var relatedProduct = await _productRepository.GetProductById(entry.RelatedProductId);

                relatedProductsList.Add(relatedProduct);
            }

            CompositeProduct.RelatedProducts = relatedProductsList;

            return(Ok(CompositeProduct));
        }
Ejemplo n.º 4
0
    protected void btnAdd_Click(object sender, ImageClickEventArgs e)
    {
        if (!ucSelectProduct.Name.Contains("|"))
        {
            ShowError("O produto integrante da composição deve ter embalagem para aparecer na lista.");
            return;
        }


        if (ucSelectProduct.Package == null)
        {
            ShowError("O produto integrante da composição deve ter embalagem para aparecer na lista.");
            return;
        }

        //
        // Populate the entity CompositeProduct to be inserted
        //
        var compositeProduct = new CompositeProduct
        {
            Amount                = Convert.ToInt32(ucCurrFieldQuantity.Text),
            CompositeProductId    = productId,
            ProductManufacturerId = ucSelectProduct.Manufacturer.ProductManufacturerId,
            ProductPackageId      = ucSelectProduct.Package.ProductPackageId,
            ProductId             = ucSelectProduct.Product.ProductId
        };

        new ProductManager(this).AddComposite(compositeProduct);
        grdComposites.DataBind();
        ucSelectProduct.Name = String.Empty;
        ucCurrFieldQuantity.CurrencyValue = null;
    }
        private void btnUpdateProduct_Click(object sender, EventArgs e)
        {
            int rowsAffected = 0;

            try
            {
                CompositeProduct compositeProduct = new CompositeProduct();
                compositeProduct.ProductId          = Int32.Parse(txtUpdateProductID.Text);
                compositeProduct.Name               = txtUpdateName.Text;
                compositeProduct.Price              = (long)numPrice.Value;
                compositeProduct.PurchasePrice      = (long)numPurchasePrice.Value;
                compositeProduct.ProductDescription = (Product_Description)cmbUpdateDescription.SelectedIndex;
                compositeProduct.Product_Status     = (Product_Status)cmbUpdateStatus.SelectedIndex;
                rowsAffected = service.UpdateProduct(compositeProduct);
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong. Please try again");
            }

            if (rowsAffected > 0)
            {
                this.Hide();
            }
            else
            {
                MessageBox.Show("Another user has already updated the product. Please try again");
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> RemoveFromCart(int id)
        {
            CompositeProduct compositeProduct = await _context.CompositeProduct.SingleOrDefaultAsync(cp => cp.CompositeProductID == id);

            _context.CompositeProduct.Remove(compositeProduct);
            await _context.SaveChangesAsync();

            return(RedirectToAction("ViewCart"));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> BuildProductAddToOrder(int inkID, int screenID, int productTypeID)
        {
            ApplicationUser user = await _userManager.GetUserAsync(User);

            Ink ink = await _context.Ink.SingleOrDefaultAsync(i => i.InkID == inkID);

            Screen screen = await _context.Screen.SingleOrDefaultAsync(s => s.ScreenID == screenID);

            ProductType productType = await _context.ProductType.SingleOrDefaultAsync(pt => pt.ProductTypeID == productTypeID);

            // Build CompositeProduct
            CompositeProduct compositeProduct = new CompositeProduct()
            {
                ProductTypeID = productTypeID, DateCreated = DateTime.Now, Price = productType.Price
            };

            if (inkID != 0 && screenID != 0)
            {
                compositeProduct.InkID    = inkID;
                compositeProduct.ScreenID = screenID;
                compositeProduct.Price   += (ink.Price + screen.Price);
            }

            // Check for open User order. If none, create new Order
            Order order = await _context.Order.SingleOrDefaultAsync(o => o.PaymentTypeID == null && o.User == user);

            if (order == null)
            {
                // Create new Order
                Order newOrder = new Order()
                {
                    User = user,
                };
                _context.Add(newOrder);
                await _context.SaveChangesAsync();

                // Add OrderID to CompositeProduct
                compositeProduct.OrderID = newOrder.OrderID;
            }
            else
            {
                // Add OrderID to CompositeProduct
                compositeProduct.OrderID = order.OrderID;
            }

            _context.Add(compositeProduct);
            await _context.SaveChangesAsync();

            return(RedirectToAction("ViewCart", "Order"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("CompositeProductID,DateCreated,ProductTypeID,InkID,ScreenID,OrderID")] CompositeProduct compositeProduct)
        {
            if (ModelState.IsValid)
            {
                _context.Add(compositeProduct);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["InkID"]         = new SelectList(_context.Ink, "InkID", "InkID", compositeProduct.InkID);
            ViewData["OrderID"]       = new SelectList(_context.Order, "OrderID", "UserId", compositeProduct.OrderID);
            ViewData["ProductTypeID"] = new SelectList(_context.ProductType, "ProductTypeID", "BaseColor", compositeProduct.ProductTypeID);
            ViewData["ScreenID"]      = new SelectList(_context.Screen, "ScreenID", "Title", compositeProduct.ScreenID);
            return(View(compositeProduct));
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                CompositeProduct product = new CompositeProduct();
                product.Name               = txtName.Text;
                product.Price              = (long)numCreateprice.Value;
                product.PurchasePrice      = (long)numCreatePurchasePrice.Value;
                product.ProductDescription = (Product_Description)cmbDescription.SelectedIndex;
                product.Product_Status     = (Product_Status)cmbStatus.SelectedIndex;

                service.CreateProduct(product);
                this.Close();
            }
            catch (CommunicationException)
            {
                MessageBox.Show("Alle felter skal udfyldes før man kan oprette et produkt");
            }
        }
Ejemplo n.º 10
0
        private void buildProducts()
        {
            //Simple product construction
            Ram4gb        = new SimpleProduct("RAM 4GB", 750, "KingStone");
            Ram8gb        = new SimpleProduct("RAM 8GB", 1000, "KingStone");
            Disk500gb     = new SimpleProduct("HDD 500GB", 1500, "ACME");
            Disk1tb       = new SimpleProduct("HDD 1TB", 2000, "ACME");
            CpuAMD        = new SimpleProduct("AMD phenon", 4000, "AMD");
            CpuIntel      = new SimpleProduct("Intel i7", 4500, "Intel");
            SmallCabinete = new SimpleProduct("Small cabinet", 2000, "ExCom");
            BigCabinete   = new SimpleProduct("Big Cabinet", 2200, "ExCom");
            Monitor20inch = new SimpleProduct("Display 20'", 1500, "HP");
            Monitor30inch = new SimpleProduct("Display 30'", 2000, "HP");
            SimpleMouse   = new SimpleProduct("Simple mouse", 150, "Genius");
            GammerMouse   = new SimpleProduct("Gammer mouse", 750, "Alien");

            //Gammer pc with 8gb ram,HDD 1tb, Intel i7 processor
            //large cabinet,display 30' and one gammer mouse.
            GammerPC = new CompositeProduct("Gammer PC");
            GammerPC.AddProduct(Ram8gb);
            GammerPC.AddProduct(Disk1tb);
            GammerPC.AddProduct(CpuIntel);
            GammerPC.AddProduct(BigCabinete);
            GammerPC.AddProduct(Monitor30inch);
            GammerPC.AddProduct(GammerMouse);

            //Home PC with RAM 4gb, HDD 500gb, AMD Phenon processor
            //small Cabinet, dsplay 20' and simple mouse.
            HomePC = new CompositeProduct("Home PC");
            HomePC.AddProduct(Ram4gb);//
            HomePC.AddProduct(Disk500gb);
            HomePC.AddProduct(CpuAMD);
            HomePC.AddProduct(SmallCabinete);
            HomePC.AddProduct(Monitor20inch);
            HomePC.AddProduct(SimpleMouse);

            //Package consisting of two packages, Gammer PC + Home PC
            Pc2x1 = new CompositeProduct("Pack PC Gammer + Home PC");
            Pc2x1.AddProduct(GammerPC);
            Pc2x1.AddProduct(HomePC);
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            var ram       = new SimpleProduct("Memoria RAM GigaBit Módulo de 16GB", 150000);
            var processor = new SimpleProduct("Intel Core i7", 750000);
            var videoCard = new SimpleProduct("nVidia GTX 1050", 1500000);
            var keyBoard  = new SimpleProduct("Keyboard generic 101 keys - Intel", 20000);
            var mouse     = new SimpleProduct("Mouse generic 3 buttons - Intel", 20000);

            var computerGeneric = new CompositeProduct("Computer Gamer Generic");

            computerGeneric.Add(ram);
            computerGeneric.Add(processor);
            computerGeneric.Add(videoCard);
            computerGeneric.Add(keyBoard);
            computerGeneric.Add(mouse);

            Console.WriteLine($"Precio de {ram.Name} es: ${ram.GetPrice().ToString("N2")}");
            Console.WriteLine($"Precio de {computerGeneric.Name} es: ${computerGeneric.GetPrice().ToString("N2")}");

            Console.ReadLine();
        }
Ejemplo n.º 12
0
        public ActionResult BuyView(FormCollection collection)
        {
            string name    = collection["Name"];
            string lAdress = collection["LAdress"];
            string phone   = collection["Phone"];
            string email   = collection["Email"];
            string zip     = collection["Zip"];
            string city    = collection["City"];
            int    intZip  = int.Parse(zip);
            List <ProductViewModel> cart            = (List <ProductViewModel>)Session["cart"];
            List <CompositeProduct> compProductList = new List <CompositeProduct>();

            foreach (ProductViewModel p in cart)
            {
                CompositeProduct compProduct = p.compositeProduct;
                compProductList.Add(compProduct);
            }
            CompositeCustomer compCustomer = CustumerCreation(name, lAdress, phone, email, intZip, city);
            string            saleString   = client.ProcessSale(compProductList, compCustomer);

            return(RedirectToAction("Payment", new { saleString }));
        }
Ejemplo n.º 13
0
        private static void CompositeScenario()
        {
            //Component
            var bolo = new CompositeProduct("Bolo");

            //Leaf
            var acucar         = new ProductComposition("Açucar");
            var farinha        = new ProductComposition("Farinha");
            var fermento       = new ProductComposition("Fermento");
            var oleo           = new ProductComposition("Oleo");
            var chocolate      = new ProductComposition("Chocolate");
            var granulado      = new ProductComposition("Granulado");
            var caldaChocolate = new ProductComposition("Calda de Chocolate");
            var leite          = new ProductComposition("Leite");
            var cremeDeLeite   = new ProductComposition("Creme de Leite");

            //Composite
            var massa = new CompositeProduct("Massa de bolo");

            massa.AddChild(acucar);
            massa.AddChild(farinha);
            massa.AddChild(oleo);
            massa.AddChild(fermento);
            massa.AddChild(leite);

            var cobertura = new CompositeProduct("Cobertura de chocolate para bolo");

            cobertura.AddChild(chocolate);
            cobertura.AddChild(acucar);
            cobertura.AddChild(granulado);
            cobertura.AddChild(caldaChocolate);
            cobertura.AddChild(cremeDeLeite);

            bolo.AddChild(massa);
            bolo.AddChild(cobertura);
            bolo.AddChild(bolo);
            bolo.ShowProducts(2);
        }
Ejemplo n.º 14
0
        //
        // Constructor. Initialises the product database.
        //
        public ProductController() : base()
        {
            // our products will be stored in a dictionary
            products = new ProductDictionaryAdapter();

            // add some test products to the database
            SimpleProduct bookByOtero       = new SimpleProduct(1, "Software Engineering Design book", 80.00M, 0.25M);
            SimpleProduct bookByMillett     = new SimpleProduct(2, "Professional ASP.NET Design Patterns book", 50.00M, 0.50M);
            SimpleProduct notesFromLectures = new SimpleProduct(3, "Lecture slides", 10.00M, 0.00M);
            SimpleProduct notesFromLabs     = new SimpleProduct(4, "Printed lab notes", 10.00M, 0.10M);

            products.Insert(bookByOtero);
            products.Insert(bookByMillett);
            products.Insert(notesFromLectures);
            products.Insert(notesFromLabs);

            // create some product packages
            CompositeProduct bookPack  = new CompositeProduct(10, "Textbook pack", bookByOtero, bookByMillett);
            CompositeProduct notesPack = new CompositeProduct(11, "Notes pack", notesFromLectures, notesFromLabs);

            products.Insert(bookPack);
            products.Insert(notesPack);
        }
Ejemplo n.º 15
0
        public void Run()
        {
            //Productos simples
            SimpleProduct ram4gb        = new SimpleProduct("RAM 4GB", "Kingston", 750);
            SimpleProduct ram8gb        = new SimpleProduct("RAM 8GB", "Adata", 1000);
            SimpleProduct disc500Gb     = new SimpleProduct("Disco duro 500GB", "WesternDigital", 1500);
            SimpleProduct disc1Tb       = new SimpleProduct("Disco duro 1 TB", "Toshiba", 2000);
            SimpleProduct cpuAMD        = new SimpleProduct("Cpu AMD phenom", "AMD", 4000);
            SimpleProduct cpuIntel      = new SimpleProduct("Cpu Intel Lake", "Intel", 4500);
            SimpleProduct bigGabinete   = new SimpleProduct("Gabinete grande", "GabGRande", 2200);
            SimpleProduct pequeGabinete = new SimpleProduct("Gabinete pequenio", "GabPequenio", 2000);
            SimpleProduct monitor20inch = new SimpleProduct("Monitor 20 pulgadas", "DELL", 1500);
            SimpleProduct monitor30inch = new SimpleProduct("Monitor 30 pulgadas", "HP", 2000);
            SimpleProduct simpleMouse   = new SimpleProduct("Mouse sencillo", "Loitech", 150);
            SimpleProduct gamerMouse    = new SimpleProduct("Mouse gamer", "Alien", 750);
            SimpleProduct keyBoard      = new SimpleProduct("Teclado", "Acme", 100);

            //Producots compuestos
            CompositeProduct keyBoardAndMouse = new CompositeProduct("KeyBoard & mouse ", 0);

            keyBoardAndMouse.AddProduct(simpleMouse); //150
            keyBoardAndMouse.AddProduct(keyBoard);    //100

            CompositeProduct package1 = new CompositeProduct("Desktop pc", 0);

            package1.AddProduct(ram4gb);           //750
            package1.AddProduct(disc500Gb);        //1500
            package1.AddProduct(cpuIntel);         //4500
            package1.AddProduct(keyBoardAndMouse); //250

            Orden orden = new Orden(1, "Alex");

            orden.addProduct(package1);
            orden.addProduct(pequeGabinete);
            orden.printOreder();
        }
Ejemplo n.º 16
0
        internal static void Composite()
        {
            Console.WriteLine("Composite Pattern Demo");
            Console.WriteLine("----------------------------");

            Composite.Product ram       = new Composite.SimpleProduct("RAM 16 gb", 1000);
            Composite.Product processor = new Composite.SimpleProduct("Intel Core i7", 2000);
            Composite.Product videoCard = new Composite.SimpleProduct("nVideo gtx 1050", 500);
            Composite.Product keyboard  = new Composite.SimpleProduct("Perfo X keyb", 1000);
            Composite.Product mouse     = new Composite.SimpleProduct("Dell x", 100);
            Composite.Product rig       = new Composite.SimpleProduct("Tower hp", 2500);
            Composite.Product led       = new Composite.SimpleProduct("Led lg", 4000);

            Composite.Product gamingKit = new CompositeProduct("Basic Gamer Computer");
            gamingKit.Add(ram);
            gamingKit.Add(processor);
            gamingKit.Add(videoCard);
            gamingKit.Add(keyboard);
            gamingKit.Add(mouse);
            gamingKit.Add(rig);
            gamingKit.Add(led);

            Console.WriteLine(gamingKit.GetPrice());
        }
 /// <summary>
 /// This method deletes a record in the table.
 /// Change this method to alter how records are deleted.
 /// </summary>
 /// <param name=entity>entity</param>
 public void Delete(CompositeProduct entity)
 {
     DbContext.CompositeProducts.DeleteOnSubmit(entity);
     DbContext.SubmitChanges();
 }
 /// <summary>
 /// This method insert a new composite product
 /// </summary>
 /// <param name="entity"></param>
 public void AddComposite(CompositeProduct entity)
 {
     DbContext.CompositeProducts.InsertOnSubmit(entity);
     DbContext.SubmitChanges();
 }
Ejemplo n.º 19
0
 public async Task <ProductTransferObject> Post(CompositeProduct entity)
 {
     return(await _httpService.Post <ProductTransferObject>($"{baseUri}api/productservice/v1/products", entity));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// This method updates a record in the table.
 /// Change this method to alter how records are updated.
 /// </summary>
 /// <param name=original_entity>original_entity</param>
 /// <param name=entity>entity</param>
 public void Update(CompositeProduct original_entity, CompositeProduct entity)
 {
     DbContext.CompositeProducts.Attach(original_entity);
     original_entity.CopyPropertiesFrom(entity);
     DbContext.SubmitChanges();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// This method inserts a new record in the table.
 /// Change this method to alter how records are inserted.
 /// </summary>
 /// <param name=entity>entity</param>
 public void Insert(CompositeProduct entity)
 {
     DbContext.CompositeProducts.InsertOnSubmit(entity);
     DbContext.SubmitChanges();
 }
 public ProductViewModel(CompositeProduct compositeProduct)
 {
     this.compositeProduct = compositeProduct;
 }