public int Add(Brand brand) { Guard.Null(brand, nameof(brand)); var result = _validator.Validate(brand); if (!result.IsValid) { throw new ValidationException(result, nameof(brand)); } _catalogDbContext.Brands.Add(brand); _catalogDbContext.SaveChanges(); return(brand.Id); }
public int Add(Product product) { Guard.Null(product, nameof(product)); var result = _productValidator.Validate(product); if (!result.IsValid) { throw new ValidationException(result, nameof(product)); } _catalogDbContext.Products.Add(product); _catalogDbContext.SaveChanges(); return(product.Id); }
public void Remove(Supplier supplier) { if (supplier == null) { throw new ArgumentNullException(nameof(supplier), "Product can not be null"); } if (supplier.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(supplier.Id), "Supplier.Id must be greater then 0"); } _catalogDbContext.Suppliers.Remove(supplier); _catalogDbContext.SaveChanges(); }