Ejemplo n.º 1
0
        public IHttpActionResult PostCustomerCategory(Models.CustomerCategory customerCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CustomerCategory.Add(customerCategory);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CustomerCategoryExists(customerCategory.IdCategory))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = customerCategory.IdCategory }, customerCategory));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutCustomerCategory(string id, Models.CustomerCategory customerCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customerCategory.IdCategory)
            {
                return(BadRequest());
            }

            db.Entry(customerCategory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetCustomerCategory(string id)
        {
            Models.CustomerCategory customerCategory = db.CustomerCategory.Find(id);
            if (customerCategory == null)
            {
                return(NotFound());
            }

            return(Ok(customerCategory));
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeleteCustomerCategory(string id)
        {
            Models.CustomerCategory customerCategory = db.CustomerCategory.Find(id);
            if (customerCategory == null)
            {
                return(NotFound());
            }

            db.CustomerCategory.Remove(customerCategory);
            db.SaveChanges();

            return(Ok(customerCategory));
        }