public bool TryRequestAnUpdate(int sellerId, ProductTypeUpdateRequest updateRequest, out ICollection <string> errors) { errors = new List <string>(); //check seller existence Seller seller = sellerRepository.GetBy(sellerId); if (seller == null) { errors.Add("Could not found seller"); } else if (seller.Status != SellerStatus.Active) //check seller status { errors.Add("Seller is unactive"); } //check product type existence ProductType productType = productTypeRepository.GetBy(updateRequest.ProductTypeId); if (productType == null) { errors.Add("Could not found product type"); } else if (productType.Status != ProductTypeStatus.Active) //check product type status { errors.Add("Product type is unavailable at the moment"); } //check category existence if (updateRequest.CategoryId != null) { Category category = categoryRepository.GetBy((int)updateRequest.CategoryId); if (category == null) { errors.Add("Could not found category"); } else if (category.ChildCategories.Any()) //check category have any childs or not { errors.Add("Category must have no childs"); } } if (string.IsNullOrWhiteSpace(updateRequest.Name)) { errors.Add("Product type name is required"); } if (string.IsNullOrWhiteSpace(updateRequest.Descriptions)) { errors.Add("Update descriptions is required"); } if (!errors.Any()) { seller.RequestUpdateForProductType(updateRequest); return(true); } return(false); }
public void DeleteProductType(int id) { var productType = productTypeRepository.GetBy(id); productTypeRepository.Delete(productType); }
public bool TryRegister(int sellerId, Product product, out ICollection <string> errors) { errors = new List <string>(); //check product null if (product == null) { errors.Add("Product can not be empty"); return(false); } if (product.Attributes != null && product.Attributes.Any()) { //check product attributes foreach (ProductAttribute attribute in product.Attributes) { if (string.IsNullOrWhiteSpace(attribute.Name)) { errors.Add("Attribute name can not be empty"); goto flag; } else { attribute.Name = attribute.Name.Trim().RemoveMultipleSpaces(); } if (string.IsNullOrWhiteSpace(attribute.Value)) { errors.Add("Attribute value can not be empty"); goto flag; } else { attribute.Value = attribute.Value.Trim().RemoveMultipleSpaces(); } } //check unique of product attributes IList <ProductAttribute> attributes = product.Attributes.ToList(); for (short i = 1; i < attributes.Count; i++) { for (short j = 0; j < i; j++) { if (attributes[i].Name == attributes[j].Name && attributes[i].Value == attributes[j].Value) { errors.Add("Each attributes must be unique"); break; } } } flag :; } if (product.RepresentativeImage == null) { errors.Add("Representative image is required"); } //check product price if (product.Price < 1) { errors.Add("Price can not lower than 1"); } //check seller existence Seller seller = sellerRepository.GetBy(sellerId); if (seller == null) { errors.Add("Could not found seller"); } else if (seller.Status != SellerStatus.Active) //check seller status { errors.Add("Seller is unactive"); } //check product type existence ProductType productType = productTypeRepository.GetBy(product.ProductTypeId); if (productType == null) { errors.Add("Could not found product type"); } else if (productType.Status != ProductTypeStatus.Active) //check product type status { errors.Add("Product type is unavailable at the moment"); } //check product type already registered if (seller != null && productType != null) { if (seller.Products.Any(p => p.ProductTypeId == productType.Id)) { errors.Add("This seller already have registered this product type"); } } if (!errors.Any()) { seller.RegisterProduct(product); return(true); } return(false); }