예제 #1
0
        public ActionResult DeleteCategory(int id)
        {
            string loggedUser = User.FindFirstValue("userId");

            if (loggedUser == null)
            {
                return(Unauthorized());
            }

            try
            {
                string categoryName = categoriesService.GetCategoryName(id);

                if (categoryName != null)
                {
                    consumptionService.ChangeCategoryIdToCategoryDefaultIdOfConsumptionsWithSameGroupIds(categoryName);
                }

                categoriesService.DeleteCategory(id);
            }
            catch (SkrillaApiException e)
            {
                if ("not_found".Equals(e.Code))
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest(e.Message));
                }
            }

            return(Accepted());
        }