Ejemplo n.º 1
0
        public IHttpActionResult GetDepartment(int locationId, int departmentId)
        {
            InventoryAgent ia = new InventoryAgent();

            if (ia.DepartmentExists(locationId, departmentId))
            {
                return(Ok(db.Departments.Find(departmentId)));
            }
            else
            {
                return(Ok("data not found"));
            }
        }
Ejemplo n.º 2
0
        // GET: api/Locations/{locationId}/Departments/{departmentId}/Categories
        public List <Category> GetCategories(int locationId, int departmentId)
        {
            InventoryAgent ia = new InventoryAgent();

            if (ia.DepartmentExists(locationId, departmentId))
            {
                return(db.Categories.ToList().FindAll(c => c.DepartmentId == departmentId));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutDepartment(int locationId, int departmentId, Department department)
        {
            if (department.LocationId != locationId)
            {
                return(Ok("different location values"));
            }

            InventoryAgent ia = new InventoryAgent();

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

                if (departmentId != department.DepartmentId)
                {
                    return(BadRequest());
                }

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

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

                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(Ok("data not found"));
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult PostCategory(int locationId, int departmentId, Category category)
        {
            if (category.DepartmentId != departmentId)
            {
                return(Ok("different department values"));
            }

            InventoryAgent ia = new InventoryAgent();

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

                db.Categories.Add(category);

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    if (CategoryExists(category.CategoryId))
                    {
                        return(Conflict());
                    }
                    else
                    {
                        throw;
                    }
                }

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

            if (ia.DepartmentExists(locationId, departmentId))
            {
                Department department = db.Departments.Find(departmentId);
                if (department == null)
                {
                    return(Ok("department not found"));
                }

                db.Departments.Remove(department);
                db.SaveChanges();

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