/// <summary> /// /// </summary> /// <param name="productVM"></param> public void UpdateProduct(ProductViewModel productVM) { product = GetProductEntityByID(productVM.ProductID); product.ProductCode = productVM.ProductCode; product.ProductTitle = productVM.ProductTitle; product.ProductDescription = productVM.ProductDescription; product.ProductShortDescription = productVM.ProductShortDescription; product.ProductStatus = productVM.ProductStatus; product.UnitPrice = productVM.UnitPrice; product.StockQuantity = productVM.StockQuantity; product.CategoryID = productVM.CategoryID; product.UserName = productVM.UserName; unitOfWork.ProductRepository.Update(product); var oldProductAttributesValueList = (from s in unitOfWork.ProductAttributesValueRepository.Get() where s.ProductID == productVM.ProductID select s).ToList(); if (oldProductAttributesValueList.Count != 0) { foreach (var item in oldProductAttributesValueList) { unitOfWork.ProductAttributesValueRepository.Delete( new ProductAttributesValue { ProductAttributesValueID = item.ProductAttributesValueID } ); } } foreach (var attribute in productVM.ProductAttributesValueList) { productAttributesValue = new ProductAttributesValue { ProductID = product.ProductID, AttributesName = attribute.AttributesName, AttributesValue = attribute.AttributesValue }; unitOfWork.ProductAttributesValueRepository.Insert(productAttributesValue); } UpdateProductSummary(productVM); unitOfWork.Save(); }
/// <summary> /// /// </summary> /// <param name="productVM"></param> /// <returns></returns> public int CreateProduct(ProductViewModel productVM) { product = new Product { ProductCode = productVM.ProductCode, ProductTitle = productVM.ProductTitle, ProductDescription = productVM.ProductDescription, ProductShortDescription = productVM.ProductShortDescription, ProductStatus = productVM.ProductStatus, UnitPrice = productVM.UnitPrice, StockQuantity = productVM.StockQuantity, CategoryID = productVM.CategoryID, UserName = productVM.UserName }; unitOfWork.ProductRepository.Insert(product); if (productVM.ProductAttributesValueList != null) { foreach (var attribute in productVM.ProductAttributesValueList) { productAttributesValue = new ProductAttributesValue { ProductID = product.ProductID, AttributesName = attribute.AttributesName, AttributesValue = attribute.AttributesValue }; unitOfWork.ProductAttributesValueRepository.Insert(productAttributesValue); } } CreateProductSummary(productVM); unitOfWork.Save(); return(product.ProductID); }