public async Task <BaseJsonResult> Update([FromBody] ProductViewModel viewModel)
        {
            var serviceModel = ProductServiceModel.FromViewModel(viewModel);

            serviceModel.User = CurrentUser;

            await _productService.UpdateProductAsync(serviceModel);

            return(new BaseJsonResult(Base.Properties.Resources.POST_SUCCEEDED, viewModel.EntityId));
        }
        private async Task Insert(FileInfo file)
        {
            using (var package = new ExcelPackage(file))
            {
                var worksheet = package.Workbook.Worksheets.FirstOrDefault();
                if (worksheet == null)
                {
                    return;
                }

                var rowCount = worksheet.Dimension.Rows;
                var ColCount = worksheet.Dimension.Columns;
                var productSeriviceCollection = new List <ProductServiceModel>();
                var products = _productService.GetProducts(new ProductFilterServiceModel());

                var addingTaxonomies = new List <TaxonomyEntity>();

                for (int row = 2; row <= rowCount; row++)
                {
                    var productTitle = worksheet.Cells[row, 2].Value?.ToString();
                    var productName  = productTitle.ToEntityName();
                    var existProduct = products.FirstOrDefault(o => o.Name == productName);
                    if (existProduct != null)
                    {
                        continue;
                    }

                    var productViewModel = new ProductViewModel()
                    {
                        Code        = worksheet.Cells[row, 1].Value?.ToString(),
                        Title       = productTitle,
                        Description = worksheet.Cells[row, 5].Value?.ToString(),
                        Dimension   = worksheet.Cells[row, 6].Value?.ToString(),
                    };

                    var price = worksheet.Cells[row, 7].Value?.ToString().Replace(".", string.Empty);
                    if (!string.IsNullOrEmpty(price))
                    {
                        productViewModel.Price = int.Parse(price);
                    }

                    var brandLabel = worksheet.Cells[row, 3].Value?.ToString();
                    if (!string.IsNullOrEmpty(brandLabel))
                    {
                        var brand = _productTaxonomiesService.GetBrandByLabel(brandLabel);
                        if (brand == null)
                        {
                            var brandName = $"{ProductTaxonomiesService.BRAND_NAME_PREFIX}-{brandLabel.ToEntityName()}";
                            brand = addingTaxonomies.FirstOrDefault(o => o.Name == brandName);
                        }

                        if (brand == null)
                        {
                            brand = _productTaxonomiesService.AddBrand(brandLabel, false);
                            addingTaxonomies.Add(brand);
                        }

                        productViewModel.BrandId = brand.Id;
                    }

                    var typeLabel = worksheet.Cells[row, 4].Value?.ToString();
                    if (!string.IsNullOrEmpty(typeLabel))
                    {
                        var type = _productTaxonomiesService.GetProductTypeByLabel(typeLabel);
                        if (type == null)
                        {
                            var typeName = $"{ProductTaxonomiesService.TYPE_NAME_PREFIX}-{typeLabel.ToEntityName()}";
                            type = addingTaxonomies.FirstOrDefault(o => o.Name == typeName);
                        }

                        if (type == null)
                        {
                            type = _productTaxonomiesService.AddProductType(typeLabel, false);
                            addingTaxonomies.Add(type);
                        }

                        productViewModel.TypeId = type.Id;
                    }

                    var serviceModel = ProductServiceModel.FromViewModel(productViewModel);
                    serviceModel.User = CurrentUser;
                    productSeriviceCollection.Add(serviceModel);
                }

                await _productService.CreateProductAsync(productSeriviceCollection);
            }
        }