Ejemplo n.º 1
0
        public HttpResponseMessage Delete(int id)
        {
            HttpResponseMessage response;
            ModelsValidation    validation = new ModelsValidation();
            VariantData         data       = new VariantData();

            if (validation.DoesVariantExist(id) == false)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "There is no variant with given Id parameter." });
            }
            else
            {
                try
                {
                    data.DeleteVariantById(id);
                    response = Request.CreateResponse(HttpStatusCode.NoContent);
                }
                catch (SqlException sqlException)
                {
                    response = CheckSqlExceptionNumber(sqlException.Number);
                }
            }

            return(response);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Put(int id, [FromBody][System.Web.Mvc.Bind(Include = "ProductId, BasePrice, Tax, InStock")] VariantModel variant)
        {
            HttpResponseMessage response;
            ModelsValidation    validation = new ModelsValidation();
            VariantData         data       = new VariantData();

            if (ModelState.IsValid)
            {
                if (validation.DoesVariantExist(id) == false)
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "There is no variant with given Id parameter." });
                }
                else
                {
                    if (validation.DoesProductExist(variant.ProductId) == false)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "There is no product with given Id parameter." });
                    }
                    else
                    {
                        data.UpdateVariantById(id, variant);
                        response = Request.CreateResponse(HttpStatusCode.NoContent);
                    }
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Model is invalid.", ModelValidation = "Product's id must be greater than 0. BasePrice, Tax and InStock must be a positive numbers." });
            }

            return(response);
        }