public IHttpActionResult GetSubCategory(int locationId, int departmentId, int categoryId, int subCategoryId) { InventoryAgent ia = new InventoryAgent(); if (ia.SubCategoryExists(locationId, departmentId, categoryId, subCategoryId)) { return(Ok(db.SubCategories.Find(subCategoryId))); } else { return(Ok("subcategory not found")); } }
public IHttpActionResult PutSubCategory(int locationId, int departmentId, int categoryId, int subCategoryId, SubCategory subCategory) { if (subCategory.CategoryId != categoryId) { return(Ok("different category values")); } InventoryAgent ia = new InventoryAgent(); if (ia.SubCategoryExists(locationId, departmentId, categoryId, subCategoryId)) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (subCategoryId != subCategory.SubCategoryId) { return(BadRequest()); } db.Entry(subCategory).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SubCategoryExists(subCategoryId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); } else { return(Ok("data not found")); } }
public IHttpActionResult DeleteSubCategory(int locationId, int departmentId, int categoryId, int subCategoryId) { InventoryAgent ia = new InventoryAgent(); if (ia.SubCategoryExists(locationId, departmentId, categoryId, subCategoryId)) { SubCategory subCategory = db.SubCategories.Find(subCategoryId); if (subCategory == null) { return(NotFound()); } db.SubCategories.Remove(subCategory); db.SaveChanges(); return(Ok(subCategory)); } else { return(Ok("data not found")); } }