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); }
/// <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); } }
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; }
public EditData(Product p, MetaProduct metaProduct, bool imageUploadAllowed) { Product = p; CurrentMetaProduct = metaProduct; CurrentMetaProductName = metaProduct.Name; ImageUploadAllowed = imageUploadAllowed; }
partial void InsertProduct(Product instance);
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; }
private void SetErrors(Product p) { Contract.Assert(p.HasErrors, "Set errors passed a valid entity."); SetModelErrors(p, "Save failed."); }
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)); }
partial void DeleteProduct(Product instance);
partial void UpdateProduct(Product instance);
/// <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); }
public UploaderData(Product product, ProductImage.PrimaryOrSecondaryOption primaryOrSecondary) { _product = product; _primaryOrSecondary = primaryOrSecondary; }
public MapViewData(Product p, string key) { ToMap = p; GoogleMapsKey = key; }
private void detach_Products(Product entity) { this.SendPropertyChanging(); entity.MetaProduct = null; }