Exemplo n.º 1
0
        /// <summary>
        /// Maps <see cref="IPublishedContent"/> to a product list item.
        /// </summary>
        /// <param name="content">
        /// The <see cref="IPublishedContent"/>
        /// </param>
        /// <param name="umbraco">
        /// The <see cref="UmbracoHelper"/>
        /// </param>
        /// <param name="product">
        /// The <see cref="ProductDisplay"/> representation of the Merchello product
        /// </param>
        /// <returns>
        /// The <see cref="ProductListItem"/>.
        /// </returns>
        public static ProductListItem ToProductListItem(this IPublishedContent content, UmbracoHelper umbraco, ProductDisplay product)
        {
            // This always for a content item (Product) to exist without a Merchello product associated.
            if (product == null)
            {
                product = new ProductDisplay()
                {
                    ProductVariants = new List <ProductVariantDisplay>(), Key = Guid.Empty, Price = 0
                };
            }

            return(new ProductListItem()
            {
                Name = content.GetSafeString("headline", content.Name),
                Description = content.GetSafeHtmlString("bodyText"),
                Thumbnail = content.GetSafeImage(umbraco, "images"),
                Images = content.GetSafeImages(umbraco, "images", null),
                ContentId = content.Id,
                Url = content.Url,
                HasVariants = product.ProductVariants.Any(),
                Price = product.Price,
                ProductKey = product.Key,
                Options = product.ProductOptions,
                AddItemFormModel = new AddItemFormModel()
                {
                    ContentId = content.Id,
                    ProductKey = product.Key,
                    Product = product,
                    Quantity = 1
                }
            });
        }
Exemplo n.º 2
0
        public IList <IResult> Handle(GetProductsByNameQuery query)
        {
            var products = _context.Products.Where(p => p.Name.Contains(query.Name, StringComparison.OrdinalIgnoreCase)).ToList();

            if (products == null)
            {
                return(null);
            }

            var results = new List <IResult>();

            foreach (var p in products)
            {
                var productDisplay = new ProductDisplay
                {
                    Id           = p.Id,
                    Name         = p.Name,
                    Description  = p.Description,
                    UnitPrice    = p.UnitPrice,
                    IsOutOfStock = p.IsOutOfStock
                };
                results.Add(productDisplay);
            }
            return(results);
        }
Exemplo n.º 3
0
        public ActionResult Edit(ProductDisplay productDisplay)
        {
            if (ModelState.IsValid)
            {
                var imgUpload = new ImageProduct();
                if (Session["avatarUploadEdit"] != null)
                {
                    foreach (var item in productDisplay.ListImage)
                    {
                        if (item.Type == 1)
                        {
                            item.Src = Session["avatarUploadEdit"].ToString();;
                        }
                    }
                }

                var result = new ProductDisplayDAO().Update(productDisplay);
                if (result == 1)
                {
                    return(RedirectToAction("Index", "Product"));
                }
                else
                {
                    ModelState.AddModelError("", "Đã xảy ra lỗi, Cập nhật không thành công!");
                }
            }
            return(View("Index"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// The formatted price.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="currency">
        /// The currency.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string FormattedPrice(this ProductDisplay display, ICurrency currency)
        {
            if (!display.ProductVariants.Any())
            {
                return(FormatPrice(display.Price, currency));
            }

            var variants   = display.ProductVariants.ToArray();
            var onsaleLow  = variants.Any(x => x.OnSale) ? variants.Where(x => x.OnSale).Min(x => x.SalePrice) : 0;
            var low        = variants.Any(x => !x.OnSale) ? variants.Where(x => !x.OnSale).Min(x => x.Price) : 0;
            var onSaleHigh = variants.Any(x => x.OnSale) ? variants.Where(x => x.OnSale).Max(x => x.SalePrice) : 0;
            var max        = variants.Any(x => !x.OnSale) ? variants.Where(x => !x.OnSale).Max(x => x.Price) : 0;

            if (variants.Any(x => x.OnSale))
            {
                low = onsaleLow < low ? onsaleLow : low;
                max = max > onSaleHigh ? max : onSaleHigh;
            }

            if (low != max)
            {
                return(string.Format(
                           "{0} - {1}",
                           FormatPrice(low, currency),
                           FormatPrice(max, currency)));
            }

            return(FormatPrice(display.Price, currency));
        }
Exemplo n.º 5
0
        public IActionResult AddCategoryToPRoduct(int id, ProductDisplay formData)
        {
            Product thisProduct = dbContext.Products
                                  .FirstOrDefault(p => p.ProductID == id);

            if (thisProduct == null)
            {
                ModelState.AddModelError("CategoryID", "No Category Selected");
            }
            if (!ModelState.IsValid)
            {
                return(Redirect($"products/{id}"));
            }

            Category addedCategory = dbContext.Categories
                                     .SingleOrDefault(c =>
                                                      c.CategoryID == formData.AddCategoryModel.NewCategoryID);

            Association asc = new Association();

            asc.Product            = thisProduct;
            asc.Category           = addedCategory;
            thisProduct.Categories = new List <Association>();
            thisProduct.Categories.Add(asc);
            addedCategory.Products = new List <Association>();
            addedCategory.Products.Add(asc);
            dbContext.SaveChanges();
            return(RedirectToAction(""));
        }
Exemplo n.º 6
0
        public ActionResult Create(ProductDisplay productDisplay)
        {
            if (ModelState.IsValid)
            {
                ImageProduct img = new ImageProduct();
                productDisplay.ListImage = new List <ImageProduct>();
                img.Src = Session["imageProduct"].ToString();
                productDisplay.ListImage.Add(img);

                productDisplay.Product.CreateDate = DateTime.Now;
                productDisplay.Product.Status     = 1;
                productDisplay.Product.Type       = 0;

                var result = new ProductDisplayDAO().Insert(productDisplay);
                if (result > 0)
                {
                    return(RedirectToAction("Index", "Product"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm mới sản phẩm không thành công!");
                }
            }
            return(View());
        }
Exemplo n.º 7
0
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            //// special case where a catalog was associated before the creation of the product
            //if (product.CatalogInventories.Any())
            //{
            //    foreach (var cat in product.CatalogInventories)
            //    {
            //        ((Product)merchProduct).MasterVariant.AddToCatalogInventory(cat.CatalogKey);
            //    }
            //}

            _productService.Save(merchProduct);

            //if (!merchProduct.ProductOptions.Any()) return merchProduct.ToProductDisplay();

            //var attributeLists = merchProduct.GetPossibleProductAttributeCombinations();

            //foreach (var list in attributeLists)
            //{
            //    _productVariantService.CreateProductVariantWithKey(merchProduct, list.ToProductAttributeCollection());
            //}

            return(merchProduct.ToProductDisplay());
        }
Exemplo n.º 8
0
        /// <summary>
        ///  [Get  List Product Category User Follows]
        /// </summary>
        /// <param name="userID">User ID</param>
        /// <returns></returns>
        public static List <ProductDisplay> GetListProductCateforyFollow(int userID, int iPage, int iSize)
        {
            List <ProductDisplay> listresult = new List <ProductDisplay>();

            var list = (from c in db.Follows
                        where (c.UserId == userID && c.Category != null)
                        select c.CategoryId);
            List <int> listtemp = new List <int>();

            foreach (var temp in list)
            {
                listtemp.Add((int)temp);
            }

            IPagedList <Product> tmp = (from c in db.Products

                                        where (c.StatusId == 2 && listtemp.Contains((int)c.CategoryId))
                                        orderby c.CreateDate descending
                                        select c).Take(100).ToPagedList(iPage, iSize);

            foreach (var c in tmp)
            {
                ProductDisplay temp = new ProductDisplay();
                temp.Name        = c.Name;
                temp.Price       = c.Price;
                temp.ProductId   = c.ProductId;
                temp.Description = c.Description.Substring(0, 30);
                temp.CategoryId  = (int)c.CategoryId;
                temp.Images      = c.ProductImages.ElementAt(0).ImageId.ToString();
                listresult.Add(temp);
            }
            return(listresult);
        }
Exemplo n.º 9
0
        public ActionResult Edit(int ID)
        {
            var productDisplay = new ProductDisplay();
            var product        = new ProductDAO().GetByID(ID);
            var imageProduct   = new ImageDAO().GetMainImgByProductID(ID);

            productDisplay.Product   = product;
            productDisplay.ListImage = new List <ImageProduct>();
            productDisplay.ListImage.Add(imageProduct);
            ViewBag.srcImgEdit = "~/Images/plus.png";

            if (TempData["pathImageEdit"] != null)
            {
                Session["avatarUploadEdit"] = TempData["pathImageEdit"];
                ViewBag.srcImgEdit          = TempData["pathImageEdit"];
            }
            else if (!string.IsNullOrEmpty(imageProduct.Src))
            {
                ViewBag.srcImgEdit          = imageProduct.Src;
                Session["avatarUploadEdit"] = imageProduct.Src;
            }
            else
            {
                ViewBag.srcImgEdit = "~/Images/plus.png";
            }
            return(View(productDisplay));
        }
Exemplo n.º 10
0
        public ActionResult ProductFiles()
        {
            var query =
                (from p in db.Product
                 join o in db.Aisle on p.aisle_id equals o.aisle_id
                 join d in db.Departments on p.department_id equals d.department_id
                 select new
            {
                Product_Id = p.product_id,
                Product_Name = p.product_name,
                Aisle_Nme = o.aisle,
                Department_Name = d.department
            }).ToList();

            List <ProductDisplay> productList = new List <ProductDisplay>();

            foreach (var prd in query)
            {
                ProductDisplay prdDis = new ProductDisplay();
                prdDis.Product_Id      = prd.Product_Id;
                prdDis.Product_Name    = prd.Product_Name;
                prdDis.Aisle_Nme       = prd.Aisle_Nme;
                prdDis.Department_Name = prd.Department_Name;
                productList.Add(prdDis);
            }

            return(View(productList));
        }
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);
            return(merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor));
        }
        /// <summary>
        /// Adds a <see cref="ProductDisplay"/> to the item cache
        /// </summary>
        /// <param name="product">
        /// The <see cref="ProductDisplay"/> to be added
        /// </param>
        /// <param name="name">
        /// Override for the name of the product in the line item
        /// </param>
        /// <param name="quantity">
        /// The quantity to be represented
        /// </param>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <remarks>
        /// If the product has variants, the "first" variant found will be added.
        /// </remarks>
        public void AddItem(ProductDisplay product, string name, int quantity, ExtendedDataCollection extendedData)
        {
            var variant = product.ProductVariants.Any() ?
                          product.ProductVariants.First() :
                          product.AsMasterVariantDisplay();

            AddItem(variant, name == product.Name ? variant.Name : name, quantity, extendedData);
        }
Exemplo n.º 13
0
        private IProduct AddProduct(ProductDisplay product)
        {
            var p = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            p = product.ToProduct(p);
            _productService.Save(p);
            return(p);
        }
Exemplo n.º 14
0
        public ActionResult ProductEntry(CreateProductModel md)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext.User.Identity.Name;
                int    ProductId   = md.FormSubmit.ProductId;
                if (ProductId == 0)
                {
                    bool returnresult = _accountService.CreateProduct(md.FormSubmit.SubCategoryId, md.FormSubmit.SupplierID,
                                                                      md.FormSubmit.ProductName, md.FormSubmit.ProductDesc,
                                                                      currentUser, md.FormSubmit.ProductType);
                    if (returnresult == true)
                    {
                        ModelState.Clear();
                        ViewBag.SuccessMsg = "Product created successfully";
                    }
                    else
                    {
                        ViewBag.SuccessMsg = "Error raised while creating product successfully";
                    }
                }
                else
                {
                    bool returnresult = _accountService.UpdateProduct(md.FormSubmit.ProductId, md.FormSubmit.SubCategoryId, md.FormSubmit.SupplierID,
                                                                      md.FormSubmit.ProductName, md.FormSubmit.ProductDesc,
                                                                      currentUser);
                    if (returnresult == true)
                    {
                        ModelState.Clear();
                        ViewBag.SuccessMsg = "Product information updated successfully";
                    }
                    else
                    {
                        ViewBag.Failuremessage = "Unable to update please try again later!";
                    }
                }
            }

            ViewBag.CategoryList    = _accountService.GetAllCategory(); //_accountService.SubCategory();
            ViewBag.SubCategoryList = _accountService.SubCategory();
            ViewBag.SupplierList    = _accountService.SupplierList();
            CreateProductModel     cpm            = new CreateProductModel();
            List <ProductDataList> AllProductData = _accountService.ProductDataList();
            ProductDisplay         model          = new ProductDisplay();

            model.ProductDataList = AllProductData;
            cpm.DisplayData       = model;
            model.ProductType     = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Return", Value = "Return"
                },
                new SelectListItem {
                    Text = "Non Return", Value = "Non Return"
                },
            };
            return(View(cpm));
        }
Exemplo n.º 15
0
        private void ProductDisplay_AddToCartClicked(object sender, EventArgs e)
        {
            // selected product
            ProductDisplay   element = sender as ProductDisplay;
            ProductViewModel item    = element.BindingContext as ProductViewModel;

            // add a shopping card item
            ((MainViewModel)this.BindingContext).ShoppingCart.IncrementOrder(item);
        }
Exemplo n.º 16
0
        public ProductDisplay GetByProductID(int productID)
        {
            var product        = new ProductDAO().GetByID(productID);
            var listImg        = new ImageDAO().GetByProductID(productID);
            var productDisplay = new ProductDisplay();

            productDisplay.Product   = product;
            productDisplay.ListImage = listImg;
            return(productDisplay);
        }
Exemplo n.º 17
0
        public ProductDisplay PutProduct(ProductDisplay product)
        {
            var merchProduct = _productService.GetByKey(product.Key);

            merchProduct = product.ToProduct(merchProduct);

            _productService.Save(merchProduct);

            return(merchProduct.ToProductDisplay());
        }
Exemplo n.º 18
0
 private object MapProductListItem(ProductDisplay product)
 {
     return(new
     {
         key = product.Key,
         name = product.Name,
         price = product.OnSale ? product.SalePrice : product.Price,
         categories = product.AsProductContent().Collections().Select(c => new { name = c.Name, key = c.Key }),
         images = this.GetImages(Umbraco.TypedMedia(this.GetDetachedValue <int>(product, "images")))
     });
 }
Exemplo n.º 19
0
        private void button5_Click(object sender, EventArgs e)
        {
            panel4.Left = ((Button)sender).Left;
            panel6.Controls.Clear();
            ProductDisplay p = new ProductDisplay(1);

            p.TopLevel = false;
            panel6.Controls.Add(p);
            p.Dock = DockStyle.Fill;
            p.Show();
        }
        /// <summary>
        /// Creates <see cref="IAddItemModel"/> from <see cref="ProductDisplay"/>.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="quantity">
        /// The quantity.
        /// </param>
        /// <returns>
        /// The <see cref="IAddItemModel"/>.
        /// </returns>
        public TAddItemModel Create(ProductDisplay display, int quantity = 1)
        {
            var addItem = new TAddItemModel
            {
                ProductKey     = display.Key,
                Quantity       = quantity,
                ProductOptions = display.ProductOptions
            };

            return(this.OnCreate(addItem, display));
        }
 /// <summary>
 /// Utility for setting the IsForBackOfficeEditor property.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <param name="conversionType">
 /// The value conversion type.
 /// </param>
 internal static void EnsureValueConversion(this ProductDisplay display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     ((ProductDisplayBase)display).EnsureValueConversion(conversionType);
     if (display.ProductVariants.Any())
     {
         foreach (var variant in display.ProductVariants)
         {
             variant.EnsureValueConversion(conversionType);
         }
     }
 }
Exemplo n.º 22
0
    void Start()
    {
        GameManager.Instance.AddCustomer();
        exitPosition = GameObject.FindGameObjectWithTag("Finish").GetComponent <Transform>().position;
        agent        = GetComponent <NavMeshAgent>();

        animator       = GetComponentInChildren <Animator>();
        productDisplay = GetComponent <ProductDisplay>();
        product        = ProductService.Instance.GetRandomProduct();

        StartCoroutine(RunWalkFreely());
    }
Exemplo n.º 23
0
        public ActionResult RenderAddToCart(ProductDisplay product)
        {
            var contentId = UmbracoContext.PageId != null ? UmbracoContext.PageId.Value : 0;

            var model = new AddItemModel()
            {
                ProductKey = product.Key,
                ContentId  = contentId
            };

            return(PartialView("RosettaAddToCart", model));
        }
Exemplo n.º 24
0
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);


            _productService.Save(merchProduct);

            return(merchProduct.ToProductDisplay());
        }
Exemplo n.º 25
0
        /// <summary>
        /// 實作加入購物車相關事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProductDisplay_AddToCartClick(object sender, EventArgs e)
        {
            //取得選到的資料
            ProductDisplay element = sender as ProductDisplay;
            Product        item    = element.BindingContext as Product;

            ((MainPageViewModel)this.BindingContext).ShoppingCart.IncrementOrder(item);

            //((MainPageViewModel)this.BindingContext).ShoppingCart.Items.Add(new ShoppingCart()
            //{
            //    Product = item
            //});
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductContent"/> class.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="parent">
        /// The parent <see cref="IPublishedContent"/>
        /// </param>
        /// <param name="isPreviewing">
        /// The is previewing.
        /// </param>
        public ProductContent(
            PublishedContentType contentType,
            ProductDisplay display,
            IPublishedContent parent = null,
            bool isPreviewing        = false)
            : base(display, contentType)
        {
            this._display      = display;
            this._parent       = parent;
            this._isPreviewing = isPreviewing;

            this.Initialize();
        }
Exemplo n.º 27
0
        public int Delete(ProductDisplay productDisplay)
        {
            var resultDeleteImage = new ImageDAO().Delete(productDisplay.ListImage);

            if (resultDeleteImage > 0)
            {
                var resultDeleteProduct = new ProductDAO().Delete(productDisplay.Product.ID);
                if (resultDeleteProduct > 0)
                {
                    return(1);
                }
            }
            return(-1);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductContent"/> class.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="parent">
        /// The parent <see cref="IPublishedContent"/>
        /// </param>
        /// <param name="specificCulture">
        /// The specific culture name
        /// </param>
        /// <param name="isPreviewing">
        /// The is previewing.
        /// </param>
        public ProductContent(
            PublishedContentType contentType,
            ProductDisplay display,
            IPublishedContent parent = null,
            string specificCulture   = "en-US",
            bool isPreviewing        = false)
            : base(display, contentType, specificCulture)
        {
            this._display      = display;
            this._parent       = parent;
            this._isPreviewing = isPreviewing;

            this.Initialize();
        }
Exemplo n.º 29
0
        public ActionResult Delete(int ID)
        {
            var productDisplay = new ProductDisplay();
            var product        = new ProductDAO().GetByID(ID);
            var imageProduct   = new ImageDAO().GetMainImgByProductID(ID);

            productDisplay.Product   = product;
            productDisplay.ListImage = new List <ImageProduct>();
            productDisplay.ListImage.Add(imageProduct);

            var result = new ProductDisplayDAO().Delete(productDisplay);

            return(View());
        }
Exemplo n.º 30
0
 private IEnumerable <object> MapVariants(ProductDisplay product)
 {
     return(product.ProductVariants?.Select(v => new
     {
         key = v.Key,
         sku = v.Sku,
         price = v.Price,
         salePrice = v.SalePrice,
         onSale = v.OnSale,
         count = v.TotalInventoryCount,
         trackCount = v.TrackInventory,
         options = this.GetOptions(v.Attributes, product.ProductOptions)
     }));
 }