private XElement ConvertToXElement(LProduct product) { PropertyInfo[] propertyInfos = product.GetType().GetProperties(); var xProduct = new XElement(NodesName.Product); foreach (var property in propertyInfos) { if (!Attribute.IsDefined(property, typeof(LNotSerializable), true)) { var xElement = new XElement(property.Name) { Value = property.GetNullValue(product) }; xProduct.Add(xElement); } if (property.PropertyType == typeof(Category)) { var xElement = new XElement(property.Name) { Value = product.Category != null ? product.Category.Name : "NULL" }; xProduct.Add(xElement); } if (property.PropertyType == typeof(ProductProperty)) { var xElement = ConvertNestedToXElement(product.ProductProperty); xProduct.Add(xElement); } } return(xProduct); }
public ProductModel(LProduct product) { if (product != null) { _product = product; _productId = product.Id; } else _product = new LProduct(); }
public ProductModel(LProduct product) { if (product != null) { _product = product; _productId = product.Id; } else { _product = new LProduct(); } }
private void UpdateCategory(LProduct product) { if(product.Category == null) return; Category category = Repository.Data.Get<Category>() .Where(x => x.Name.Equals(product.Category.Name)).FirstOrDefault().Value; if (category == null) Repository.Data.Save(product.Category); else product.Category = category; }
public static LProduct CopyFrom(this LProduct source, ProductModel product, bool update) { source.Name = product.Name; source.Price = product.Price; if (update) { source.ProductProperty.CopyFrom(product.ProductProperty); } source.StockBalance = product.StockBalance; source.UpdateDate = DateTime.Now; source.CreateDate = source.CreateDate; source.Category = source.Category; source.Description = source.Description; return(source); }
private IEnumerable <XElement> ConvertProductToXElementForOrder(LProduct product) { PropertyInfo[] propertyInfos = product.GetType().GetProperties(); var xProduct = new List <XElement>(); foreach (var info in propertyInfos) { if (info.Name.InvariantEquals("Name") || info.Name.InvariantEquals("Article")) { var xElement = new XElement(info.Name); xElement.Value = info.GetNullValue(product); xProduct.Add(xElement); } } return(xProduct); }
private void UpdateCategory(LProduct product) { if (product.Category == null) { return; } Category category = Repository.Data.Get <Category>() .Where(x => x.Name.Equals(product.Category.Name)).FirstOrDefault().Value; if (category == null) { Repository.Data.Save(product.Category); } else { product.Category = category; } }
private ProductModel ConvertFrom(Litium.Domain.Entities.ProductCatalog.Product product) { return(new ProductModel(product)); }
public ProductModel() { _product = new LProduct(); }
public Product ProductCreateTest() { var product = new Product { Name = "Product " + _testGuid.ToString(), Category = CategoryCreateTest(), CreateDate = _createTestDate, Description = "Description1", Price = 10.00m, ProductProperty = ProductPropertyCreateTest(), Published = false, StockBalance = 10, UpdateDate = _createTestDate }; Repository.Data.Save(product); Assert.True(product.Id != Guid.Empty); return product; }
private LProduct CreateProductFromXElement(XElement element) { LProduct product = null; if (!String.IsNullOrWhiteSpace(element.Element(NodesName.Article).Value)) { product = Repository.Data.Get <LProduct>() .Where(x => x.Article.Equals(element.Element(NodesName.Article).Value, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value; } if (product == null) { product = new LProduct { CreateDate = DateTime.Now } } ; product.UpdateDate = DateTime.Now; product.LastSynchDate = DateTime.Now; PropertyInfo[] propertyInfos = product.GetType().GetProperties(); foreach (var info in propertyInfos) { if (element.Element(info.Name) != null) { if (info.PropertyType == typeof(ProductProperty)) { product.ProductProperty = CreateProductPropertyFromXElement(element.Element(NodesName.ProductProperty)); continue; } if (info.PropertyType == typeof(Category)) { product.Category = CreateCategoryFromXElement(element); continue; } if (info.PropertyType == typeof(Decimal)) { Decimal result; Decimal.TryParse(element.Element(info.Name).Value, out result); info.SetValue(product, result, null); continue; } if (info.PropertyType == typeof(Int32)) { Int32 result; Int32.TryParse(element.Element(info.Name).Value, out result); info.SetValue(product, result, null); continue; } info.SetValue(product, element.Element(info.Name).Value, null); } } return(product); }