Exemple #1
0
        public async Task <ProductOutput> SaveProduct(ProductInput saveProduct)
        {
            Product product;

            if (saveProduct.Id.HasValue)
            {
                product = await _productRepository.GetAsync(saveProduct.Id.Value);

                product = saveProduct.MapTo(product);
                if (saveProduct.IsSet)
                {
                    IEnumerable <SetProductInput> newSetProducts = saveProduct.SetProductsInput.Where(x => !x.Id.HasValue);
                    foreach (SetProductInput newSetProduct in newSetProducts)
                    {
                        product.SetProducts.Add(newSetProduct.MapTo <SetProduct>());
                    }
                }
                await _productRepository.UpdateAsync(product);
            }
            else
            {
                product = saveProduct.MapTo <Product>();
                if (saveProduct.IsSet)
                {
                    product.SetProducts = saveProduct.SetProductsInput.MapTo <List <SetProduct> >();
                }
                await _productRepository.InsertAndGetIdAsync(product);
            }

            return(product.MapTo <ProductOutput>());
        }
Exemple #2
0
        public Guid AddProductToStore(ProductInput input)
        {
            var     slug     = input.ProductName.CreateSlug();
            var     tenantId = AbpSession.TenantId ?? 1;
            Product instance;

            if (input.Id.HasValue)
            {
                instance = _productManager.GetProduct(input.Id.Value);
                instance.SetSlug(instance.ProductName.CreateSlug());
                instance = input.MapTo(instance);
            }
            else
            {
                instance = Product.CreateProduct(input.ProductName,
                                                 input.AvailableStock,
                                                 input.TrackStock,
                                                 input.ProductPrice,
                                                 input.ProductDescription,
                                                 input.Sku,
                                                 input.IsFeatured,
                                                 input.ProductName.CreateSlug());
                if (input.Active)
                {
                    instance.Active = input.Active;
                }
            }

            if (input.Imagen.ContentLength > 0)
            {
                //Small image
                var formatedFolderSmall = string.Format(ImageFolder, tenantId, slug, FolderSizeSmall);
                var smallImage          = _imageManager.SaveImage(250, 250, input.Imagen, formatedFolderSmall);
                //Medium Image
                var formatedFolderMed = string.Format(ImageFolder, tenantId, slug, FolderSizeMedium);
                var medImage          = _imageManager.SaveImage(650, 350, input.Imagen, formatedFolderMed);

                //Default Image
                var formatedFolderDef = string.Format(ImageFolder, tenantId, slug, FolderSizeDefault);
                var defImage          = _imageManager.SaveImage(null, null, input.Imagen, formatedFolderDef);


                instance.SetMainImage(defImage);
                instance.SetMedImage(medImage);
                instance.SetSmallImage(smallImage);
                instance.SetDataImage(input.DataImage);
            }


            var id = _productManager.AddProduct(instance);

            return(id);
        }
Exemple #3
0
        public int CreateProductAsync(ProductInput input)
        {
            var Id      = 0;
            var product = input.MapTo <Product>();
            var val     = _productRepository.GetAll().Where(p => p.ProductName == input.ProductName || p.ProductCode == input.ProductCode || p.SuspectCode == input.SuspectCode || p.Gpcode == input.Gpcode).FirstOrDefault();

            if (val == null)
            {
                Id = _productRepository.InsertAndGetId(product);
            }
            else
            {
                throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in MileProduct Name '" + input.ProductName + "' or Product Code '" + input.ProductCode + "' or Suspect Code '" + input.SuspectCode + "' or Gp Code '" + input.Gpcode + "'...");
            }
            return(Id);
        }
Exemple #4
0
        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task AddProductAsync(ProductInput input)
        {
            var product = input.MapTo <Product>();

            if (input.Id.HasValue)
            {
                product             = _productRepository.Get(input.Id.Value);
                product.CategoryId  = input.CategoryId;
                product.Description = input.Description;
                product.Name        = input.Name;
                product.Package     = input.Package;
                product.Sort        = input.Sort;
                FileRelationRepository.Delete(x => x.KeyId == input.Id.Value && (x.ModuleId == ModuleType.ProductMan || x.ModuleId == ModuleType.ProductDetail));
            }
            else
            {
                product = _productRepository.Insert(product);
                CurrentUnitOfWork.SaveChanges();
            }
            await AddFileRelationAsync(input.ProductImage, product.Id, ModuleType.ProductMan);
            await AddFileRelationAsync(input.StyleImage, product.Id, ModuleType.ProductDetail);
        }