Exemplo n.º 1
0
        public void AddItem(Product.Product product, int quantity)
        {
            if (product == null)
            {
                throw new ArgumentNullException($"{nameof(product)} cannot be null.");
            }

            if (quantity < 1)
            {
                throw new ArgumentException($"{nameof(quantity)} must be greater than 0.");
            }

            var inCartProductMaybe = lineItems.FirstOrDefault(l => l.Product.ID == product.ID);

            if (inCartProductMaybe == null)
            {
                lineItems.Add(new LineItem(product, quantity));
                return;
            }

            //ASSUMPTION: last added product has the most current information
            lineItems.Remove(inCartProductMaybe);

            var inCartProductQuantity = inCartProductMaybe.Quantity;

            lineItems.Add(new LineItem(product, quantity + inCartProductQuantity));
        }
Exemplo n.º 2
0
 public Offer
 (
     Guid id,
     string number,
     Product.Product product,
     Person customer,
     Person driver,
     Car car,
     TimeSpan coverPeriod,
     Money totalCost,
     DateTime creationDate,
     IDictionary <Cover, Money> coversPrices
 )
 {
     Id           = id;
     Number       = number;
     Status       = OfferStatus.New;
     ProductCode  = product.Code;
     Customer     = customer;
     Driver       = driver;
     Car          = car;
     CoverPeriod  = coverPeriod;
     TotalCost    = totalCost;
     CreationDate = creationDate;
     foreach (var coverWithPrice in coversPrices)
     {
         covers.Add(new CoverPrice(Guid.NewGuid(), coverWithPrice.Key, coverWithPrice.Value, coverPeriod));
     }
 }
Exemplo n.º 3
0
        public async Task <ProductSellerDetail> Get(EntityDto <long> input)
        {
            //var seller = await GetCurrentSeller();
            Product.Product product = await ProductManager.Get(input.Id, 0);

            System.Collections.Generic.IEnumerable <ImageDto> images = product.ProductImages.Select(s => new ImageDto
            {
                Id  = s.Image.Id,
                Url = s.Image.Url
            });

            return(new ProductSellerDetail
            {
                Id = product.Id,
                BrandId = product.BrandId,
                CoverImageUrl = product.CoverImage?.Image?.Url,
                CoverImageId = product.CoverImage?.Image?.Id,
                Description = product.Description,
                ImageIds = product.ProductImages?.Where(s => s.Image != null).Select(s => s.Image.Id).ToArray(),
                ImageUrls = product.ProductImages?.Where(s => s.Image != null).Select(s => s.Image.Url).ToArray(),
                Name = product.Name,
                Price = product.Price,
                SellerId = product.SellerId,
                Images = images.ToList(),
                CategoryIds = product.ProductCategories?.Select(s => s.CategoryId).ToArray()
            });
        }
Exemplo n.º 4
0
        public Domain.Offer.Offer CalculateOffer(IDiscountCalculator discountCalculator, IProductRepository productRepository)
        {
            if (_status != OrderStatus.New)
            {
                throw new NotFoundException();
            }

            List <OfferItem> availabeItems    = new List <OfferItem>();
            List <OfferItem> unavailableItems = new List <OfferItem>();

            decimal totalCost = 0;

            foreach (var orderItem in _products)
            {
                Product.Product product = productRepository.Get(orderItem.ProductId);
                if (product.Aviable)
                {
                    OfferItem offerItem = new OfferItem(product.Id, product.Name, product.Price, product.ProductType);

                    availabeItems.Add(offerItem);
                    totalCost += offerItem.Price;
                }
                else
                {
                    OfferItem offerItem = new OfferItem(product.Id, product.Name, product.Price, product.ProductType);

                    unavailableItems.Add(offerItem);
                }
            }

            decimal discount = discountCalculator.Calculate(availabeItems);

            return(new Domain.Offer.Offer(_clientId, totalCost - discount, discount, availabeItems, unavailableItems));
        }
Exemplo n.º 5
0
        public string Run()
        {
            switch (Code.ToLower())
            {
            case Constants.CreateProduct:
                var product = new Product.Product(Arguments);
                Context.Products.Add(product);
                return($"Product created; code {product.Code}, price {product.Price}, stock {product.Stock}");

            case Constants.CreateCampaign:
                var campaign = new Campaign.Campaign(Arguments);
                Context.Campaigns.Add(campaign);
                return($"Campaign created; name {campaign.Name}, product {campaign.Product.Code}, duration {campaign.Duration}, limit {campaign.PML}, target sales count {campaign.Target}");

            case Constants.CreateOrder:
                var order = new Order.Order(Arguments);
                Context.Orders.Add(order);
                return($"Order created; product {order.Product.Code}, quantity {order.Quantity}");

            case Constants.CampaignInfo:
                var infoCampaign = Context.Campaigns.FirstOrDefault(i => i.Name.ToLower() == Arguments[1].ToLower());
                return(infoCampaign?.GetInfo() ?? "The campaign you were looking for could not be found.");

            case Constants.ProductInfo:
                var infoProduct = Context.Products.FirstOrDefault(i => i.Code.ToLower() == Arguments[1].ToLower());
                return(infoProduct?.GetInfo() ?? "The product you are looking for could not be found.");

            case Constants.IncreaseTime:
                Context.Time.Increase(Arguments);
                return($"Time is {Context.Time.DateTime.ToShortTimeString()}");

            default:
                return("Command not detected.");
            }
        }
 public Task <TransactionProduct> CreateAsync(Product.Product product, Transaction.Transaction transaction)
 {
     return(Task.Factory.StartNew(() =>
     {
         var transactionProduct = new TransactionProduct(product, transaction);
         return transactionProduct;
     }));
 }
Exemplo n.º 7
0
        public OrdinaryShopProductCountBuilder New(Product.Product product, float newCount)
        {
            var shopProduct
                = OrdinaryShop.ManagerOfShopProducts.Build().TrackedProducts[product.Id];

            shopProduct.Count = newCount;
            return(this);
        }
Exemplo n.º 8
0
 public CartItem(Product.Product product, Quantity quantity)
 {
     ProductId   = product.Id;
     SKU         = product.SKU;
     Description = product.Description;
     Price       = product.Price;
     Quantity    = quantity;
 }
Exemplo n.º 9
0
        public OrdinaryShopProductPriceBuilder New(Product.Product product, float newPrice)
        {
            var shopProduct
                = OrdinaryShop.ManagerOfShopProducts.Build().TrackedProducts[product.Id];

            shopProduct.Price = newPrice;
            return(this);
        }
Exemplo n.º 10
0
        //double click on product row and open product detail window
        private void productClick(object sender, EventArgs e)
        {
            int productId = int.Parse(productListView.SelectedItems[0].SubItems[0].Text);

            Product.Product product = productManager.getProductById(productId, loggedUser.email, loggedUser.password);
            productDetail   detail  = new productDetail(product, loggedUser, this);

            detail.Show();
        }
Exemplo n.º 11
0
        public OrdinaryShopProductPriceBuilder ChangeOn(Product.Product product,
                                                        float priceChange)
        {
            var shopProduct
                = OrdinaryShop.ManagerOfShopProducts.Build().TrackedProducts[product.Id];

            shopProduct.Price += priceChange;
            return(this);
        }
Exemplo n.º 12
0
        public OrdinaryShopProductCountBuilder ChangeOn(Product.Product product,
                                                        float countChange)
        {
            var shopProduct
                = OrdinaryShop.ManagerOfShopProducts.Build().TrackedProducts[product.Id];

            shopProduct.Count += countChange;
            return(this);
        }
Exemplo n.º 13
0
 public Item(Product.Product product, int vol)
 {
     this.Thing = product;
     ChangeVolume(vol);
     Cost           = new Product.Money(0.0f, Product.Waluta.PLN);
     Value          = Cost.Value;
     NameOfCurrency = Cost.NameOfCurrency;
     IdProdukt      = Thing.IDProduct;
 }
Exemplo n.º 14
0
 public void Add(Product.Product product, int count = 1)
 {
     if (product != null)
     {
         for (int i = 0; i < count; i++)
         {
             Products.Add(product);
         }
     }
 }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Product.Product product = null;

            var creator = new ConcreteCreator();

            product = creator.FactoryMethod();

            creator.AnOperation();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Default Constructor.
 /// </summary>
 public ShoppingCartProduct(Product.Product product)
 {
     Id                         = product.Id;
     Name                       = product.Name;
     MainImagePath              = product.MainImage.ImagePath;
     Quantity                   = 1;
     PurchaseSettings           = product.PurchaseSettings;
     SelectedCheckoutProperties = new List <CheckoutPropertySettingKey>();
     CheckoutPropertySetting    = new CheckoutPropertySetting();
     PrivateCartUniqueId        = string.Empty;
 }
Exemplo n.º 17
0
        public Item()
        {
            Random rand = new Random();

            Cost           = new Product.Money();
            Thing          = new Product.Product();
            Volume         = rand.Next(1, 100);
            IdProdukt      = rand.Next(1, 100);
            Value          = Cost.Value;
            NameOfCurrency = Cost.NameOfCurrency;
        }
Exemplo n.º 18
0
        //product create button
        private void createProduct_Click(object sender, EventArgs e)
        {
            //create empty product
            Product.Product newProduct = new Product.Product();
            newProduct.ID          = 0;
            newProduct.brand       = new Product.Brand();
            newProduct.brand.ID    = 0;
            newProduct.category    = new Product.Category();
            newProduct.category.ID = 0;
            productEdit editProductForm = new productEdit(newProduct, this);

            editProductForm.Show();
        }
Exemplo n.º 19
0
        public void Add(Product.Product product, Quantity quantity)
        {
            var item = _items.Find(itemToSearch => itemToSearch.SKU == product.SKU);

            if (item != null)
            {
                item.IncreaseQuantity(quantity);
            }
            else
            {
                var itemToAdd = new CartItem(product, quantity);
                _items.Add(itemToAdd);
            }
        }
Exemplo n.º 20
0
        private bool AddProduct(Product.Product pProduct)
        {
            var cartItem = new Models.Cart.CartItem()
            {
                Id              = pProduct.Id,
                Name            = pProduct.Name,
                Price           = pProduct.Price,
                DefaultImageURL = pProduct.DefaultImageURL,
                Quantity        = 1
            };

            this.Items.Add(cartItem);
            return(true);
        }
Exemplo n.º 21
0
        public void AddItem(Product.Product product, int quantity)
        {
            CartAtributes prod = cartProds.FirstOrDefault(p => p.Product.ProductId == product.ProductId);

            if (prod == null)
            {
                cartProds.Add(new CartAtributes {
                    Product = product, Quantity = quantity
                });
            }
            else
            {
                prod.Quantity += quantity;
            }
        }
Exemplo n.º 22
0
        private static string MakeStr(Product.Product product, int count)
        {
            string result;

            if (product.IsKilograms())
            {
                result = product.Name + " - " + count + " kilograms" + "\n";
            }
            else
            {
                result = product.Name + " - " + count + " pieces" + "\n";
            }

            return(result);
        }
Exemplo n.º 23
0
        public void Remove(Product.Product product, Quantity quantity)
        {
            var item = _items.Find(itemToSearch => itemToSearch.SKU == product.SKU);

            if (item == null)
            {
                throw new ItemNotFoundException(product);
            }

            item.DecreaseQuantity(quantity);

            if (item.Quantity == Quantity.Zero)
            {
                _items.Remove(item);
            }
        }
Exemplo n.º 24
0
 public void Verify(string[] args)
 {
     try
     {
         int actionTime = Context.Time.Hour;
         ActionTime     = actionTime;
         Product        = Context.Products.SingleOrDefault(i => i.Code.ToLower() == args[1].ToLower()) ?? throw new Exception();
         UnitPrice      = Product.Price;
         Quantity       = int.Parse(args[2]);
         Product.Stock -= Quantity;
     }
     catch
     {
         throw new CommandException(601, "There was an error creating the order.");
     }
 }
Exemplo n.º 25
0
        public IEnumerable <Policy> Get(Product.Product product)
        {
            var applicablePoclies = new List <Policy>();

            switch (product.Category)
            {
            case ProductCategory.Food:
                applicablePoclies.Add(new Policy()
                {
                    TaxRate = 0, Type = PolicyCategory.FoodSalesTaxPolicy
                });
                break;

            case ProductCategory.Books:
                applicablePoclies.Add(new Policy()
                {
                    TaxRate = 0, Type = PolicyCategory.BooksSalesTaxPolicy
                });
                break;

            case ProductCategory.Medicines:
                applicablePoclies.Add(new Policy()
                {
                    TaxRate = 0, Type = PolicyCategory.MedicinesSalesTaxPolicy
                });
                break;

            default:
                applicablePoclies.Add(new Policy()
                {
                    TaxRate = 10.00m, Type = PolicyCategory.NonExemptedSalesTaxPolicy
                });
                break;
            }

            if (product.IsImported)
            {
                applicablePoclies.Add(new Policy()
                {
                    TaxRate = 5.00M, Type = PolicyCategory.ImportedDutySalesTaxPolicy
                });
            }

            return(applicablePoclies);
        }
Exemplo n.º 26
0
        public void AddItem(Product.Product product, int quantity)
        {
            if (product is null)
            {
                throw new ArgumentNullException("Product is null");
            }
            if (quantity <= 0)
            {
                throw new ArgumentOutOfRangeException("Quantity must be greater than 0");
            }
            if (_products.ContainsKey(product))
            {
                _products[product] += quantity;
                return;
            }

            _products.Add(product, quantity);
        }
Exemplo n.º 27
0
        public productEdit(Product.Product product, adminPanel adminForm)
        {
            this.product    = product;
            this.adminPanel = adminForm;
            InitializeComponent();
            MaterialSkinManager materialUIManager = MaterialSkinManager.Instance;

            materialUIManager.AddFormToManage(this);
            materialUIManager.Theme = MaterialSkinManager.Themes.LIGHT;

            materialUIManager.ColorScheme = new ColorScheme(
                Primary.Blue400, Primary.Blue500,
                Primary.Blue500, Accent.Orange200,
                TextShade.WHITE
                );
            productBrand.DisplayMember    = "name";
            productBrand.ValueMember      = "ID";
            productCategory.DisplayMember = "name";
            productCategory.ValueMember   = "ID";
            this.loadProduct();
        }
Exemplo n.º 28
0
        //if id is 0 then i'm going to create a new product. if id != 0 then i update the selected product
        public bool updateProduct(Product.Product product)
        {
            bool result;

            if (product.ID != 0)
            {
                result = this.productManager.updateProduct(this.loggedUser.email, this.loggedUser.password, product);
            }
            else
            {
                result = this.productManager.createProduct(this.loggedUser.email, this.loggedUser.password, product);
            }
            if (result)
            {
                this.loadProducts();
            }
            else
            {
                MessageBox.Show("Errore all'aggiornameto/creazione del prodotto");
            }
            return(result);
        }
Exemplo n.º 29
0
        public productDetail(Product.Product product, User.User loggedUser, userHome userForm)
        {
            this.userForm   = userForm;
            this.product    = product;
            this.loggedUser = loggedUser;
            InitializeComponent();
            MaterialSkinManager materialUIManager = MaterialSkinManager.Instance;

            materialUIManager.AddFormToManage(this);
            materialUIManager.Theme = MaterialSkinManager.Themes.LIGHT;

            materialUIManager.ColorScheme = new ColorScheme(
                Primary.Blue400, Primary.Blue500,
                Primary.Blue500, Accent.Orange200,
                TextShade.WHITE
                );
            namePlaceholder.Text        = product.name;
            descriptionPlaceHolder.Text = product.description;
            pricePlaceHolder.Text       = product.price.ToString() + " (" + product.tax.ToString() + "%)";
            brandPlaceHolder.Text       = product.brand.name;
            categoryPlaceHolder.Text    = product.category.name;
            productImage.ImageLocation  = product.image;
        }
Exemplo n.º 30
0
        //add product to cart
        public void addToCart(Product.Product product)
        {
            //increase product qty or create new cart row
            bool found = false;

            foreach (ListViewItem item in cartListView.Items)
            {
                if (item.SubItems[0].Text == product.ID.ToString())
                {
                    found = true;
                    int updatedQty = int.Parse(item.SubItems[3].Text);
                    updatedQty++;
                    item.SubItems[3].Text = updatedQty.ToString();
                }
            }
            if (!found)
            {
                cartListView.Items.Add(new ListViewItem(new string[] { product.ID.ToString(), product.name, product.price.ToString(), "1" }));
            }
            this.computeCartTotal();
            cartListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            cartListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }