public void UpsertAttribute_InsertSecond()
        {
            Mock<IProductRepository> productRepo = new Mock<IProductRepository>();
            Mock<IImageResizer> imageResizer = new Mock<IImageResizer>();
            ProductService service = new ProductService(productRepo.Object, imageResizer.Object, ServiceBuilder.Saver.Object);
            Product oneAtt = new Product();
            MetaAttribute cost = new MetaAttribute();
            cost.Id = 3;
            cost.DataTypeEnum = MetaAttribute.MetaAttributeDataType.CURRENCY;

            MetaAttribute height = new MetaAttribute();
            height.Id = 6;
            height.DataTypeEnum = MetaAttribute.MetaAttributeDataType.INTEGER;

            ProductAttribute costAtt = new ProductAttribute();
            costAtt.Id = 2;
            costAtt.MetaAttribute = cost;
            oneAtt.ProductAttributes.Add(costAtt);

            ProductAttribute heightAtt = new ProductAttribute();
            heightAtt.Id = 8;
            heightAtt.MetaAttribute = height;

            productRepo.Expect(repo => repo.CreateProductAttribute(height)).Returns(heightAtt);
            service.UpsertAttribute(oneAtt, height, "69");

            Assert.AreEqual(2, oneAtt.ProductAttributes.Count);
        }
        public void UpsertAttribute_Clear()
        {
            ProductService service = SetupProductService();
            Product oneAtt = new Product();
            MetaAttribute cost = new MetaAttribute();
            cost.Id = 3;
            cost.DataTypeEnum = MetaAttribute.MetaAttributeDataType.CURRENCY;
            ProductAttribute costAtt = new ProductAttribute();
            costAtt.Id = 2;
            costAtt.MetaAttribute = cost;
            oneAtt.ProductAttributes.Add(costAtt);

            service.UpsertAttribute(oneAtt, cost, "");
            Assert.AreEqual(1, oneAtt.ProductAttributes.Count);
        }
        public void UpsertAttribute_Insert()
        {
            Mock<IProductRepository> productRepo = new Mock<IProductRepository>();
            ProductService service = SetupProductService();
            Product noAtts = new Product();
            MetaAttribute metaAttribute = new MetaAttribute();
            metaAttribute.Id = 5;
            metaAttribute.DataTypeEnum = MetaAttribute.MetaAttributeDataType.STRING;

            service.UpsertAttribute(noAtts, metaAttribute, "");
            Assert.IsTrue(noAtts.ProductAttributes.Count == 0);

            ProductAttribute catAtt = new ProductAttribute();
            catAtt.Id = 1;
            catAtt.MetaAttribute = metaAttribute;
            catAtt.Product = noAtts;

            productRepo.Expect(repo => repo.CreateProductAttribute(metaAttribute)).Returns(catAtt);

            service.UpsertAttribute(noAtts, metaAttribute, "cat");
            Assert.AreEqual(1, noAtts.ProductAttributes.Count);
        }
Example #4
0
        /// <summary>See IProductService.</summary>
        /// <param name="metaAttribute"></param><param name="value"></param>
        public void UpsertAttribute(Product p, MetaAttribute metaAttribute, string value)
        {
            if (p.HasAttributeFor(metaAttribute.Id))
            {
                // update
                ProductAttribute att = p.GetAttribute(metaAttribute.Id);
                if (value.Equals(String.Empty))
                {
                    saver.MarkForDeletion(att);
                }
                else att.SetFormattedValue(value);
            }
            else
            {
                // insert
                if (value.Equals(String.Empty)) return; // no value entered.

                ProductAttribute att = _productRepository.CreateProductAttribute(metaAttribute);
                p.ProductAttributes.Add(att);
                att.SetFormattedValue(value);
            }
        }
Example #5
0
 public ActionResult New()
 {
     Product p = new Product();
     return View("New", new EditData(p, _metaProductRepo.CurrentMetaProduct, false));
 }
 public MessageItemBuilder WithProduct(Product product)
 {
     defaultProduct = product;
     return this;
 }
Example #7
0
 public EditData(Product p, MetaProduct metaProduct, bool imageUploadAllowed)
 {
     Product = p;
     CurrentMetaProduct = metaProduct;
     CurrentMetaProductName = metaProduct.Name;
     ImageUploadAllowed = imageUploadAllowed;
 }
Example #8
0
 partial void InsertProduct(Product instance);
Example #9
0
        private bool SaveProduct(Product p)
        {
            var errorCollection = new List<ValidationFailure>();

            try { UpdateModel(p, new[] {"Name", "Description", "Address"}); }
            catch (HttpRequestValidationException)
            {
                errorCollection.Add(new ValidationFailure(String.Empty, "Request validation error.", String.Empty));
                p.AddValidationFailure(errorCollection);
                SetErrors(p);
                return false;
            }

            errorCollection.AddRange(ValidateAttributeValues());
            if (errorCollection.Count > 0)
            {
                p.AddValidationFailure(errorCollection);
                SetErrors(p);
                return false;
            }

            // product attributes are all valid
            foreach (MetaAttribute ma in _metaProductRepo.CurrentMetaProduct.MetaAttributes)
            {
                string formValue = Request.Form[ma.ProductAttributeHtmlControlName];
                if (formValue != null)
                {
                    _productService.UpsertAttribute(p, ma, formValue);
                }
            }

            if (!p.IsValid)
            {
                SetErrors(p);
                return false;
            }

            // entire product is valid!
            saver.SaveAll();
            SetSuccessMessage(_metaProductRepo.CurrentMetaProduct.Name + " saved.");
            return true;
        }
Example #10
0
 private void SetErrors(Product p)
 {
     Contract.Assert(p.HasErrors, "Set errors passed a valid entity.");
     SetModelErrors(p, "Save failed.");
 }
Example #11
0
 private void DeleteProduct(Product toDelete)
 {
     int productId = toDelete.Id;
     string productName = toDelete.Name;
     _productService.DeleteProduct(toDelete.Id);
     saver.SaveAll();
     SetSuccessMessage(String.Format("Product {0}({1}) successfully deleted.", productName, productId));
 }
Example #12
0
 partial void DeleteProduct(Product instance);
Example #13
0
 partial void UpdateProduct(Product instance);
Example #14
0
 /// <summary>Delete all of the image files belonging to the product.</summary>
 /// <param name="toDelete"></param>
 private void DeleteProductsFiles(Product toDelete)
 {
     foreach (ProductImage image in toDelete.ProductImages) DeleteProductImageFiles(image);
 }
Example #15
0
 public UploaderData(Product product, ProductImage.PrimaryOrSecondaryOption primaryOrSecondary)
 {
     _product = product;
     _primaryOrSecondary = primaryOrSecondary;
 }
Example #16
0
 public MapViewData(Product p, string key)
 {
     ToMap = p;
     GoogleMapsKey = key;
 }
Example #17
0
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.MetaProduct = null;
		}