Ejemplo n.º 1
0
        // GET: api/Locations/{locationId}/Departments/{departmentId}/Categories/{categoryId}/SubCategories
        public List <SubCategory> GetSubCategories(int locationId, int departmentId, int categoryId)
        {
            InventoryAgent ia = new InventoryAgent();

            if (ia.CategoryExists(locationId, departmentId, categoryId))
            {
                return(db.SubCategories.ToList().FindAll(sc => sc.CategoryId == categoryId));
            }
            else
            {
                return(new List <SubCategory>());
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetCategory(int locationId, int departmentId, int categoryId)
        {
            InventoryAgent ia = new InventoryAgent();

            if (ia.CategoryExists(locationId, departmentId, categoryId))
            {
                return(Ok(db.Categories.Find(categoryId)));
            }
            else
            {
                return(Ok("category not found"));
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutCategory(int locationId, int departmentId, int categoryId, Category category)
        {
            if (category.DepartmentId != departmentId)
            {
                return(Ok("different department values"));
            }

            InventoryAgent ia = new InventoryAgent();

            if (ia.CategoryExists(locationId, departmentId, categoryId))
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (categoryId != category.CategoryId)
                {
                    return(BadRequest());
                }

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

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

                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(Ok("data not found"));
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult PostSubCategory(int locationId, int departmentId, int categoryId, SubCategory subCategory)
        {
            if (subCategory.CategoryId != categoryId)
            {
                return(Ok("different department values"));
            }

            InventoryAgent ia = new InventoryAgent();

            if (ia.CategoryExists(locationId, departmentId, categoryId))
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                db.SubCategories.Add(subCategory);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    if (SubCategoryExists(subCategory.SubCategoryId))
                    {
                        return(Conflict());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(CreatedAtRoute("DefaultApi", new { id = subCategory.SubCategoryId }, subCategory));
            }
            else
            {
                return(Ok("data not found"));
            }
        }
Ejemplo n.º 5
0
        public IHttpActionResult DeleteCategory(int locationId, int departmentId, int categoryId)
        {
            InventoryAgent ia = new InventoryAgent();

            if (ia.CategoryExists(locationId, departmentId, categoryId))
            {
                Category category = db.Categories.Find(categoryId);
                if (category == null)
                {
                    return(Ok("category not found"));
                }

                db.Categories.Remove(category);
                db.SaveChanges();

                return(Ok(category));
            }
            else
            {
                return(Ok("data not found"));
            }
        }