Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 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));
     }
 }