/*Update Product Detail */ public ServiceResponse UpdateProduct(ProductModel productModel) { var product = new Product(); var productAccountPrice = new List<ProductAccountPrice>(); var productAvailability = new List<ProductAvailability>(); var productPricingInfo = new List<ProductPricing>(); var productDivision = new List<ProductDivision>(); var productCategory = new List<ProductCategory>(); var productinfo = _unitOfWork.productRespository.Get(m => m.ProductId == productModel.ProductId).FirstOrDefault(); var productDivisionInfo = _unitOfWork.productDivisionRespository.Get(m => m.ProductId == productModel.ProductId); var productCategoryInfo = _unitOfWork.productCategoryRespository.Get(m => m.ProductId == productModel.ProductId); var productAttributeInfo= _unitOfWork.productAttributeRespository.Get(m => m.ProductId == productModel.ProductId); // var productAccountPriceInfo = _unitOfWork.productAccountPriceRespository.Get(m => m.ProductId == productModel.ProductId); var productAvailabilityInfo = _unitOfWork.productAvailabilityRespository.Get(m => m.ProductId == productModel.ProductId); Mapper.Map(productModel, productinfo); Mapper.Map(productModel.ProductAccountPriceModel, product.ProductAccountPrice); Mapper.Map(productModel.ProductAvailabilityModel, product.ProductAvailability); Mapper.Map(productModel.ProductPricingModel, product.ProductPricing); Mapper.Map(productModel.ProductDivisionModel, product.ProductDivision); Mapper.Map(productModel.ProductCategoryModel, product.ProductCategory); Mapper.Map(productModel.ProductAttributeModel, product.ProductAttribute); if (product.ProductPricing.Count > 0) { var deleteProduct = product.ProductPricing.Where(m => m.IsDeleted == true && m.ProductPricingId != 0).ToList(); if (deleteProduct.Count > 0) _unitOfWork.productPricingRespository.DeleteAll(deleteProduct); productPricingInfo = product.ProductPricing.Where(m => m.ProductPricingId == 0 && m.IsDeleted == false).ToList(); if (productPricingInfo.Count > 0) { product.ProductPricing.ToList().ForEach(m => m.UpdatedBy = GetLoginUserId()); _unitOfWork.productPricingRespository.InsertAll(productPricingInfo); } } if (product.ProductAccountPrice.Count > 0) { var deleteProduct = product.ProductAccountPrice.Where(m => m.IsDeleted == true && m.ProductAccountPriceId != 0).ToList(); if (deleteProduct.Count > 0) _unitOfWork.productAccountPriceRespository.DeleteAll(deleteProduct); productAccountPrice = product.ProductAccountPrice.Where(m => m.ProductAccountPriceId == 0 && m.IsDeleted == false).ToList(); if (productAccountPrice.Count > 0) { product.ProductPricing.ToList().ForEach(m => m.UpdatedBy = GetLoginUserId()); _unitOfWork.productAccountPriceRespository.InsertAll(productAccountPrice); } } var deleteProductAvail = productAvailabilityInfo.Where(m => !product.ProductAvailability.Any(y => y.AvailabilityId== m.AvailabilityId)).ToList(); productAvailability = product.ProductAvailability.Where(m => !productAvailabilityInfo.Any(y => y.AvailabilityId == m.AvailabilityId)).ToList(); if (deleteProductAvail.Count > 0) _unitOfWork.productAvailabilityRespository.DeleteAll(deleteProductAvail); if (productAvailability.Count > 0) _unitOfWork.productAvailabilityRespository.InsertAll(productAvailability); var deleteProductDivision = productDivisionInfo.Where(m => !product.ProductDivision.Any(y => y.DivisionId == m.DivisionId)).ToList(); productDivision = product.ProductDivision.Where(m => !productDivisionInfo.Any(y => y.DivisionId == m.DivisionId)).ToList(); if (deleteProductDivision.Count > 0) _unitOfWork.productDivisionRespository.DeleteAll(deleteProductDivision); if (productDivision.Count > 0) _unitOfWork.productDivisionRespository.InsertAll(productDivision); var deleteProductCategory= productCategoryInfo.Where(m => !product.ProductCategory.Any(y => y.CategoryId == m.CategoryId)).ToList();//Which records are not selected productCategory = product.ProductCategory.Where(m => !productCategoryInfo.Any(y => y.CategoryId == m.CategoryId)).ToList();//which records are selected if (deleteProductCategory.Count > 0) _unitOfWork.productCategoryRespository.DeleteAll(deleteProductCategory); if (productCategory.Count > 0) _unitOfWork.productCategoryRespository.InsertAll(productCategory); var deleteProductAttr= productAttributeInfo.Where(m => !product.ProductAttribute.Any(y => y.AttributeId== m.AttributeId)).ToList();//Which records are not selected productAttributeInfo = product.ProductAttribute.Where(m => !productAttributeInfo.Any(y => y.AttributeId == m.AttributeId)).ToList();//which records are selected if (deleteProductAttr.Count > 0) _unitOfWork.productAttributeRespository.DeleteAll(deleteProductAttr); if (productAttributeInfo.Count > 0) _unitOfWork.productAttributeRespository.InsertAll(productAttributeInfo); //if (productAccountPriceInfo.Count > 0) //{ // _unitOfWork.productAccountPriceRespository.DeleteAll(productAccountPriceInfo); // productAccountPriceInfo = product.ProductAccountPrice.ToList(); // product.ProductAccountPrice.ToList().ForEach(m => m.UpdatedBy = GetLoginUserId()); // _unitOfWork.productAccountPriceRespository.InsertAll(productAccountPriceInfo); //} //if (productAvailabilityInfo.Count > 0) //{ // _unitOfWork.productAvailabilityRespository.DeleteAll(productAvailabilityInfo); // productAvailabilityInfo = product.ProductAvailability.ToList(); // _unitOfWork.productAvailabilityRespository.InsertAll(productAvailabilityInfo); //} ////if (productDivisionInfo.Count > 0) //// _unitOfWork.productDivisionRespository.DeleteAll(productDivisionInfo); ////productDivisionInfo = product.ProductDivision.ToList(); ////product.ProductPricing.ToList().ForEach(m => m.UpdatedBy = GetLoginUserId()); ////_unitOfWork.productDivisionRespository.InsertAll(productDivisionInfo); //var results = persons2.Where(m => !diffids.Contains(m.Id)).ToList() //var insertList1 = productPricingInfo.Where(m =>!product.ProductPricing.Contains(m.ProductId)).ToList(); //productPricingInfo = insertList; //var rateShipmentList = productPricingInfo.Where(m => product.ProductPricing.Any(y => y.ProductId!= m.ProductId)).ToList(); //var rateShipmentList1 = product.ProductPricing.Where(m => productPricingInfo.Any(y => y.ProductId != m.ProductId)).ToList(); //if (productPricingInfo.Count > 0) // _unitOfWork.productPricingRespository.DeleteAll(productPricingInfo); productinfo.UpdatedBy = GetLoginUserId(); _unitOfWork.productRespository.Update(productinfo); _unitOfWork.Save(); Mapper.Map(productinfo, productModel); Mapper.Map(product.ProductAccountPrice, productModel.ProductAccountPriceModel); Mapper.Map(product.ProductAvailability, productModel.ProductAvailabilityModel); Mapper.Map(product.ProductPricing, productModel.ProductPricingModel); Mapper.Map(product.ProductDivision, productModel.ProductDivisionModel); Mapper.Map(product.ProductCategory, productModel.ProductCategoryModel); Mapper.Map(product.ProductAttribute, productModel.ProductAttributeModel); return new ServiceResponse { Data = productModel, Message = "Update", Success = true }; }
public ProductModel UpdateProductStatus(ProductModel productModel) { var product = new Product(); Mapper.Map(productModel, product); _unitOfWork.productRespository.Update(product); _unitOfWork.Save(); Mapper.Map(product, productModel); return productModel; }
/*Add New Product Detail*/ public ServiceResponse SaveProduct(ProductModel productModel) { var product = new Product(); var productAccountPrice = new ProductAccountPrice(); var productAvailability = new ProductAvailability(); var productPricing = new ProductPricing(); Mapper.Map(productModel, product); Mapper.Map(productModel.ProductAccountPriceModel, product.ProductAccountPrice); Mapper.Map(productModel.ProductAvailabilityModel, product.ProductAvailability); Mapper.Map(productModel.ProductPricingModel, product.ProductPricing); Mapper.Map(productModel.ProductDivisionModel, product.ProductDivision); Mapper.Map(productModel.ProductCategoryModel, product.ProductCategory); Mapper.Map(productModel.ProductAttributeModel, product.ProductAttribute); product.CreatedBy = GetLoginUserId(); product.ProductAccountPrice.ToList().ForEach(m => m.CreatedBy = GetLoginUserId()); product.ProductPricing.ToList().ForEach(m => m.CreatedBy = GetLoginUserId()); _unitOfWork.productRespository.Insert(product); _unitOfWork.Save(); Mapper.Map(product, productModel); Mapper.Map(product.ProductClass, productModel.ProductClassModel); Mapper.Map(product.ProductAccountPrice, productModel.ProductAccountPriceModel); Mapper.Map(product.ProductAvailability, productModel.ProductAvailabilityModel); Mapper.Map(product.ProductPricing, productModel.ProductPricingModel); Mapper.Map(product.ProductDivision, productModel.ProductDivisionModel); Mapper.Map(product.ProductCategory, productModel.ProductCategoryModel); Mapper.Map(product.ProductAttribute, productModel.ProductAttributeModel); return new ServiceResponse { Success = true, Message = "Saved", Data = productModel }; }