public int CreateProduct(string name, string price, bool isAvailable, string brandId, string categoryId) { var nameValidated = ValidateName(name); var priceValidated = ValidatePrice(price); var brandValidated = ValidateId(brandId, "Brand"); var categoryValidated = ValidateId(categoryId, "Category"); var productDal = new ProductDal(); return(productDal.CreateProduct(nameValidated, priceValidated, isAvailable, brandValidated, categoryValidated)); }
public IHttpActionResult Post(Products products) { if (ModelState.IsValid) { var createdProduct = productDal.CreateProduct(products); return(CreatedAtRoute("DefaultApi", new { id = createdProduct.ProductID }, createdProduct)); } else { return(BadRequest(ModelState)); } }