예제 #1
0
        public string ImportCategory([FromBody] ContentTierImportViewModel viewModel)
        {
            var product = _productSvc.GetByMappingId(viewModel.MappingId);

            if (product != null)
            {
                bool hasChanges = false;
                foreach (var contentTier in viewModel.ContentTiers)
                {
                    if (!product.ContentTiers.Any(e => e.Name == contentTier.Name))
                    {
                        hasChanges = true;
                        var newCategory = new Business.Modules.Product.Model.ContentTier
                        {
                            Name     = contentTier.Name,
                            Brands   = contentTier.Brands,
                            TitleIds = contentTier.TitleIds
                        };

                        product.ContentTiers.Add(newCategory);
                    }

                    if (hasChanges)
                    {
                        _productSvc.Save(product);
                    }
                }
            }


            return("Success");
        }
예제 #2
0
        public ContentTierViewModel Post([FromBody] ContentTierViewModel viewModel)
        {
            List <ProductViewModel> destinations = new List <ProductViewModel>();

            foreach (var product in viewModel.Products)
            {
                Business.Modules.Product.Model.Product productDetail = null;

                if (!string.IsNullOrEmpty(product.Name))
                {
                    productDetail = _productSvc.GetById(product.ExternalId);
                }
                if (productDetail != null)
                {
                    if (!string.IsNullOrEmpty(product.ContentTiers.First().Name))
                    {
                        if (!string.IsNullOrEmpty(product.ContentTiers.First().Id))
                        {
                            var category = productDetail.ContentTiers.FirstOrDefault(e => e.Id == product.ContentTiers.First().Id);

                            category.Name     = product.ContentTiers.First().Name;
                            category.Brands   = product.ContentTiers.First().Brands;
                            category.TitleIds = product.ContentTiers.First().TitleIds;
                        }
                        else
                        {
                            var contentTier = new Business.Modules.Product.Model.ContentTier
                            {
                                Name     = product.ContentTiers.First().Name,
                                Brands   = product.ContentTiers.First().Brands,
                                TitleIds = product.ContentTiers.First().TitleIds
                            };

                            productDetail.ContentTiers.Add(contentTier);
                        }
                    }
                    else
                    {
                        productDetail.ContentTiers.RemoveAll(e => e.Id == product.ContentTiers.First().Id);
                    }

                    var blModel = _productSvc.Save(productDetail);

                    destinations.Add(blModel.ToViewModel <Business.Modules.Product.Model.Product, ProductViewModel>());
                }
            }

            var newModel = new ContentTierViewModel();

            newModel.Id = viewModel.Id;
            if (newModel.Id == null)
            {
                newModel.Id = new Guid().ToString();
            }
            newModel.Name = viewModel.Name;

            var newProducts = new List <ProductViewModel>();

            foreach (var product in viewModel.Products)
            {
                if (product.ContentTiers.Any() && !string.IsNullOrWhiteSpace(product.ContentTiers.First().Name))
                {
                    newProducts.Add(product);
                }
            }

            newModel.Products = newProducts;

            return(newModel);
        }