Admin.AdminProductResponse Admin.IAdminCatalogManager.SaveProduct(int catalogId, Admin.Product product)
        {
            try
            {
                // authenticate the user as a seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    // map to the accessor DTO
                    DTO.Product accProduct = new DTO.Product();
                    DTOMapper.Map(product, accProduct);

                    accProduct = AccessorFactory.CreateAccessor <ICatalogAccessor>().SaveProduct(catalogId, accProduct);

                    if (accProduct != null)
                    {
                        Admin.Product result = new Admin.Product();
                        DTOMapper.Map(accProduct, result);

                        return(new Admin.AdminProductResponse()
                        {
                            Success = true,
                            Product = result
                        });
                    }
                    return(new Admin.AdminProductResponse()
                    {
                        Success = false,
                        Message = "Product not saved"
                    });
                }
                return(new Admin.AdminProductResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new Admin.AdminProductResponse()
                {
                    Success = false,
                    Message = "There was a problem saving the product"
                });
            }
        }
Beispiel #2
0
        public Product SaveProduct(int catalogId, Product product)
        {
            // map the catalog id in the ambient context to the product parameter
            if (product.CatalogId == 0)
            {
                product.CatalogId = catalogId;
            }

            using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create())
            {
                EntityFramework.Product model = null;
                if (product.Id > 0)
                {
                    model = db.Products.Find(product.Id);
                    if (model == null)
                    {
                        Logger.Error("Product Id not found");
                        throw new ArgumentException("Product Id not found");
                    }
                    // verify the db product belongs to the current catalog and matches the product input catalog
                    if (model != null && (model.CatalogId != product.CatalogId || model.CatalogId != catalogId))
                    {
                        Logger.Error("Catalog Id mismatch");
                        throw new ArgumentException("Catalog Id mismatch");
                    }
                    DTOMapper.Map(product, model);
                }
                else
                {
                    model = new EntityFramework.Product();
                    DTOMapper.Map(product, model);
                    db.Products.Add(model);
                }
                db.SaveChanges();

                return(DTOMapper.Map <Product>(model));
            }
        }
        WebStore.WebStoreProductResponse WebStore.IWebStoreCatalogManager.ShowProduct(int catalogId, int productId)
        {
            try
            {
                WebStore.ProductDetail result     = new WebStore.ProductDetail();
                DTO.Product            catProduct = AccessorFactory.CreateAccessor <ICatalogAccessor>().FindProduct(productId);

                if (catProduct != null)
                {
                    if (catProduct.CatalogId == catalogId)
                    {
                        DTOMapper.Map(AccessorFactory.CreateAccessor <ICatalogAccessor>().FindProduct(productId), result);

                        return(new WebStore.WebStoreProductResponse()
                        {
                            Success = true,
                            Product = result
                        });
                    }
                }
                return(new WebStore.WebStoreProductResponse()
                {
                    Success = false,
                    Message = "Product not found"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                return(new WebStore.WebStoreProductResponse()
                {
                    Success = false,
                    Message = "There was a problem accessing the product"
                });
            }
        }