Пример #1
0
        public List <SubCategoryAdmin> UpdateSubCategory(SubCategory subcategory)
        {
            List <SubCategoryAdmin> subcategories = new List <SubCategoryAdmin>();

            try
            {
                subcategories = _subcategory_object.UpdateSubCategory(subcategory);

                if (subcategories != null)
                {
                    return(subcategories);
                }
                else
                {
                    throw new OASCustomException("Operation failed.");
                }
            }
            catch (SqlException sqlex)
            {
                log.Error(sqlex);
            }
            catch (OASCustomException customex)
            {
                log.Error(customex.Message);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return(subcategories);
        }
        public async Task <HttpResponseMessage> UpdateSubCategory(int id, [FromBody] SubCategory subCategory)
        {
            try
            {
                SubCategory subcat = await subCatOp.getSubCategoryById(id);

                if (subcat == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "SubCategory with Id = " + id.ToString() + " not found to update"));
                }
                else
                {
                    await subCatOp.UpdateSubCategory(id, subCategory);

                    return(Request.CreateResponse(HttpStatusCode.OK, subcat));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }