Esempio n. 1
0
        public static ProductFullView ConvertToProductFullView(ecom_Products product)
        {
            var productFullView = new ProductFullView()
            {
                Id                = product.Id,
                ProductCode       = product.ProductCode,
                Name              = product.Name,
                Price             = product.Price,
                Quantity          = product.Quantity,
                Unit              = product.Unit,
                BrandId           = product.BrandId,
                CoverImageId      = product.CoverImageId,
                Description       = product.Description,
                Description2      = product.Description2,
                Specification     = product.Specification,
                TotalView         = product.TotalView,
                TotalBuy          = product.TotalBuy,
                Tags              = product.Tags,
                IsNewProduct      = product.IsNewProduct,
                IsBestSellProduct = product.IsBestSellProduct,
                SortOrder         = product.SortOrder,
                Status            = product.Status,
                //CreatedBy = product.CreatedBy.to,
                //CreatedDate = product.CreatedDate,
                //ModifiedBy = product.ModifiedBy,
                //ModifiedDate = product.ModifiedDate
                //share_Images = product.share_Images.ConvertToImageProductViewModels()
            };

            return(productFullView);
        }
Esempio n. 2
0
        /// <summary>
        /// Add new product to database
        /// </summary>
        /// <returns></returns>
        public bool AddProduct(CreateProductPostRequest newProduct)
        {
            try
            {
                ecom_Products product = new ecom_Products()
                {
                    ProductCode  = newProduct.ProductCode != null?newProduct.ProductCode:"",
                    Name         = newProduct.Name,
                    Price        = newProduct.Price,
                    Quantity     = newProduct.Quantity,
                    Unit         = newProduct.Unit,
                    BrandId      = newProduct.BrandId,
                    CoverImageId = newProduct.CoverImageId,
                    Description  = newProduct.Description,
                    Description2 = newProduct.Description2,
                    //Tags = newProduct.Tags,
                    Tags              = "",
                    IsNewProduct      = newProduct.IsNewProduct,
                    IsBestSellProduct = newProduct.IsBestSellProduct,
                    SortOrder         = newProduct.SortOrder,
                    Status            = newProduct.Status
                };

                share_Images coverImage = imageRepository.GetByID(newProduct.CoverImageId);
                product.share_Images.Add(coverImage);
                db.Insert(product);
                db.Save();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 3
0
        public void Update(ecom_Products product, int quantity)
        {
            var line = LineCollection.FirstOrDefault(x => x.Product.Id == product.Id);

            if (line != null)
            {
                line.Quantity = quantity;
            }
        }
Esempio n. 4
0
        public void Delete(ecom_Products product)
        {
            var line = LineCollection.FirstOrDefault(x => x.Product.Id == product.Id);

            if (line != null)
            {
                LineCollection.Remove(line);
            }
        }
        /// <summary>
        /// Get details product
        /// </summary>
        /// <param name="id">id of product</param>
        /// <returns>Product details object</returns>
        public ProductDetailsView GetProductDetails(int id)
        {
            ecom_Products product = db.GetProductById(id);

            if (product == null)
            {
                return(null);
            }
            else
            {
                ProductDetailsView productViewModel = new ProductDetailsView()
                {
                    Id                = product.Id,
                    ProductCode       = product.ProductCode,
                    Name              = product.Name,
                    Price             = String.Format(System.Globalization.CultureInfo.GetCultureInfo("vi-VN"), "{0:C0}", product.Price),
                    BrandName         = product.ecom_Brands != null ? product.ecom_Brands.Name : "",
                    Description       = product.Description,
                    Description2      = product.Description2,
                    Tags              = product.Tags,
                    IsNewProduct      = product.IsNewProduct,
                    IsBestSellProduct = product.IsBestSellProduct,
                    Quantity          = product.Quantity,
                };

                ImageInfor coverImage;
                if (product.CoverImage != null)
                {
                    coverImage = new ImageInfor()
                    {
                        smallImagePath = product.CoverImage.ImagePath,
                        largeImagePath = GetLargeProductImagePathFromSmallImage(product.CoverImage.ImageName)
                    };
                }
                else
                {
                    coverImage = new ImageInfor()
                    {
                        smallImagePath = "/Content/Images/no-image.png",
                        largeImagePath = "/Content/Images/no-image.png"
                    };
                }


                List <ImageInfor> productImages = product.share_Images.Select(i => new ImageInfor()
                {
                    smallImagePath = i.ImagePath,
                    largeImagePath = GetLargeProductImagePathFromSmallImage(i.ImageName)
                }).ToList();

                productViewModel.CoverImageUrl = coverImage;
                productViewModel.share_Images  = productImages;

                return(productViewModel);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Create list product image for return to client side
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        ///

        public ActionResult ListImageProduct(int productId)
        {
            ecom_Products product = service.GetProductById(productId);
            ListImageProductPartialViewModels listImageViewModels = new ListImageProductPartialViewModels()
            {
                ProductId    = productId,
                Images       = product.share_Images.ConvertToImageProductViewModels(),
                CoverImageId = product.CoverImageId
            };

            return(PartialView("ListImageProduct", listImageViewModels));
        }
Esempio n. 7
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ecom_Products product = service.GetProductById((int)id);

            int[] listCategory;
            int[] listProductGroup;

            if (product == null)
            {
                return(HttpNotFound());
            }

            // Populate status dropdownlist
            if (product.Status != null)
            {
                var status = (Define.Status)product.Status;
                PopulateStatusDropDownList(status);
            }
            else
            {
                PopulateStatusDropDownList();
            }
            // Populate category dropdownlist
            if (product.ecom_Categories.Count > 0)
            {
                listCategory = product.ecom_Categories.Select(c => c.Id).ToArray();
            }
            else
            {
                listCategory = null;
            }
            // Populate product group dropdownlist
            if (product.ecom_ProductGroups.Count > 0)
            {
                listProductGroup = product.ecom_ProductGroups.Select(c => c.Id).ToArray();
            }
            else
            {
                listProductGroup = null;
            }
            ViewBag.BrandId       = PopulateListBrand(product.BrandId);
            ViewBag.Categories    = PopulateListCategory(listCategory);
            ViewBag.ProductGroups = PopulateListProductGroup(listProductGroup);
            return(View(product.ConvertToProductFullView()));
        }
Esempio n. 8
0
 public bool VerifyProduct(int id, int status)
 {
     try
     {
         ecom_Products product = GetProductById(id);
         product.Status = status;
         db.Save();
         RefreshAll();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Delete product (set Status is Delete)
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool DeleteProduct(int id)
 {
     try
     {
         ecom_Products product = GetProductById(id);
         product.Status = (int)Define.Status.Delete;
         db.Save();
         RefreshAll();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Add image for exist product
        /// </summary>
        /// <param name="IdProduct">product id</param>
        /// <param name="photo">new image</param>
        /// <param name="listImages"> return list image after adding finish</param>
        /// <returns>return true if action is success or false action is fail</returns>
        public bool AddImageForProduct(int IdProduct, share_Images photo)
        {
            ecom_Products product = db.GetProductById(IdProduct);

            if (product == null)
            {
                return(false);
            }
            else
            {
                product.share_Images.Add(photo);
                db.Save();
                return(true);
            }
        }
Esempio n. 11
0
        public static ProductSummaryView ConvertToProductSummaryView(this ecom_Products product)
        {
            ProductSummaryView productSummaryView = new ProductSummaryView()
            {
                Id               = product.Id,
                Name             = product.Name,
                BrandName        = product.ecom_Brands != null? product.ecom_Brands.Name:"",
                Price            = String.Format(System.Globalization.CultureInfo.GetCultureInfo("vi-VN"), "{0:C0}", product.Price),
                CoverImageUrl    = product.CoverImage != null ? product.CoverImage.ImagePath : DisplayProductConstants.NoImagePath,
                IsNew            = product.IsNewProduct,
                ShortDescription = product.Description
            };

            return(productSummaryView);
        }
Esempio n. 12
0
 /// <summary>
 /// Set as cover image of product
 /// </summary>
 /// <param name="productId"></param>
 /// <param name="imageId"></param>
 /// <param name="listImages"></param>
 /// <returns></returns>
 public bool SetAsCoverImage(int productId, int imageId)
 {
     try
     {
         ecom_Products product = GetProductById(productId);
         product.CoverImageId = imageId;
         db.Update(product);
         db.Save();
         RefreshAll();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 13
0
        public void Add(ecom_Products product, int quantity)
        {
            var model = LineCollection.FirstOrDefault(x => x.Product.Id == product.Id);

            if (model == null)
            {
                CartLineViewModel line = new CartLineViewModel()
                {
                    Product = product, Quantity = quantity
                };
                LineCollection.Add(line);
            }
            else
            {
                model.Quantity += 1;
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Delete image in product
 /// </summary>
 /// <param name="productId">product id</param>
 /// <param name="imageId">id of image need to delete</param>
 /// <param name="listImages">list images of product after do action</param>
 /// <param name="imagePath">path of deteled image(using for delete image in folder)</param>
 /// <returns>return true if action is success or false if action is fail</returns>
 public bool DeleteImage(int productId, int imageId, out share_Images deleteImages)
 {
     try
     {
         ecom_Products product = GetProductById(productId);
         share_Images  image   = product.share_Images.Where(i => i.Id == imageId).SingleOrDefault();
         deleteImages = image;
         //Delete image in product
         product.share_Images.Remove(image);
         db.Save();
         // Delete image in table share_images
         var deleteImage = imageRepository.GetByID(imageId);
         imageRepository.Delete(deleteImage);
         imageRepository.Save();
         return(true);
     }
     catch (Exception)
     {
         deleteImages = null;
         return(false);
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Delete product (set Status is Delete)
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool DeleteProduct(int id, string deleteBy, bool isAdmin)
 {
     try
     {
         ecom_Products product = GetProductById(id);
         if (isAdmin == true)
         {
             product.Status = (int)Define.Status.Delete;
         }
         else
         {
             product.Status = (int)Define.Status.WaitingDelete;
         }
         product.ModifiedTy = deleteBy;
         db.Save();
         RefreshAll();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 16
0
        /// <summary>
        /// update image information of product
        /// </summary>
        /// <param name="productId">product id</param>
        /// <param name="image">image id</param>
        /// <param name="isCoverImage">is cover image of product or not</param>
        /// <param name="listImages">list images of product returned</param>
        /// <returns></returns>
        public bool UpdateProductImage(int productId, OnlineStore.Service.Messaging.UpdateProductImage imageInfor, bool isCoverImage)
        {
            try
            {
                share_Images image = imageRepository.GetByID(imageInfor.ImageId);
                image.ImageName = imageInfor.Name;
                image.Status    = imageInfor.IsActive ? (int)Define.Status.Active : (int)Define.Status.Deactive;


                ecom_Products product = db.GetProductById(productId);
                if (isCoverImage)
                {
                    //product.CoverImageId = image.Id;
                    product.CoverImage = image;
                }
                else
                {
                    if (product.CoverImageId == image.Id)
                    {
                        //product.CoverImageId = null;
                        product.CoverImage = null;
                    }
                }
                imageRepository.Update(image);
                db.Update(product);
                db.Save();
                imageRepository.Save();
                RefreshAll();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Update product
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public bool UpdateProduct(ProductFullView productViewModel)
        {
            ecom_Products product = db.GetProductById(productViewModel.Id);

            if (product == null)
            {
                return(false);
            }
            else
            {
                product.ProductCode       = productViewModel.ProductCode;
                product.Name              = productViewModel.Name;
                product.Price             = productViewModel.Price;
                product.Quantity          = productViewModel.Quantity;
                product.Unit              = productViewModel.Unit;
                product.BrandId           = productViewModel.BrandId;
                product.Description       = productViewModel.Description;
                product.Description2      = productViewModel.Description2;
                product.Tags              = productViewModel.Tags;
                product.IsNewProduct      = productViewModel.IsNewProduct;
                product.IsBestSellProduct = productViewModel.IsBestSellProduct;
                product.SortOrder         = productViewModel.SortOrder;
                product.Status            = productViewModel.Status;
                product.ModifiedDate      = DateTime.Now;

                if (productViewModel.CategoryId == null)
                {
                    product.ecom_Categories = new List <ecom_Categories>();
                }
                else
                {
                    var selectedCategories = new HashSet <int>(productViewModel.CategoryId);
                    var categoriesProduct  = new HashSet <int>(product.ecom_Categories.Select(c => c.Id));
                    foreach (var category in categoryRepository.GetAllCategories())
                    {
                        if (selectedCategories.Contains(category.Id))
                        {
                            if (!categoriesProduct.Contains(category.Id))
                            {
                                product.ecom_Categories.Add(category);
                            }
                        }
                        else
                        {
                            if (categoriesProduct.Contains(category.Id))
                            {
                                product.ecom_Categories.Remove(category);
                            }
                        }
                    }
                }
                if (productViewModel.ProductGroupId == null)
                {
                    product.ecom_ProductGroups = new List <ecom_ProductGroups>();
                }
                else
                {
                    var selectedGroups = new HashSet <int>(productViewModel.ProductGroupId);
                    var GroupsProduct  = new HashSet <int>(product.ecom_ProductGroups.Select(g => g.Id));
                    foreach (var group in productGroupRepository.GetAllAvailableGroups())
                    {
                        if (selectedGroups.Contains(group.Id))
                        {
                            if (!GroupsProduct.Contains(group.Id))
                            {
                                product.ecom_ProductGroups.Add(group);
                            }
                        }
                        else
                        {
                            if (GroupsProduct.Contains(group.Id))
                            {
                                product.ecom_ProductGroups.Remove(group);
                            }
                        }
                    }
                }

                db.Save();
                RefreshAll();
                return(true);
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Add new product to database
 /// </summary>
 /// <returns></returns>
 public bool AddProduct(CreateProductPostRequest newProduct)
 {
     try
     {
         ecom_Products product = new ecom_Products()
         {
             ProductCode       = newProduct.ProductCode,
             Name              = newProduct.Name,
             Price             = newProduct.Price,
             Quantity          = newProduct.Quantity,
             Unit              = newProduct.Unit,
             BrandId           = newProduct.BrandId,
             CoverImageId      = newProduct.CoverImageId,
             Description       = newProduct.Description,
             Description2      = newProduct.Description2,
             Tags              = newProduct.Tags,
             IsNewProduct      = newProduct.IsNewProduct,
             IsBestSellProduct = newProduct.IsBestSellProduct,
             SortOrder         = newProduct.SortOrder,
             Status            = newProduct.Status,
             CreateTy          = newProduct.CreateBy,
             CreatedDate       = DateTime.Now,
             TotalBuy          = 0
         };
         if (newProduct.CategoryId == null)
         {
             product.ecom_Categories = new List <ecom_Categories>();
         }
         else
         {
             var selectedCategories = new HashSet <int>(newProduct.CategoryId);
             var categoriesProduct  = new HashSet <int>(product.ecom_Categories.Select(c => c.Id));
             foreach (var category in categoryRepository.GetAllCategories())
             {
                 if (selectedCategories.Contains(category.Id))
                 {
                     if (!categoriesProduct.Contains(category.Id))
                     {
                         product.ecom_Categories.Add(category);
                     }
                 }
                 else
                 {
                     if (categoriesProduct.Contains(category.Id))
                     {
                         product.ecom_Categories.Remove(category);
                     }
                 }
             }
         }
         share_Images coverImage = imageRepository.GetByID(newProduct.CoverImageId);
         product.share_Images.Add(coverImage);
         db.Insert(product);
         db.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }