Example #1
0
        public IHttpActionResult Delete(int id)
        {
            var household = HouseholdHelper.GetByIdWithCategories(id);

            if (household == null)
            {
                return(NotFound());
            }

            var currentUserId = User.Identity.GetUserId();
            var IsOwner       = household.IsOwner(currentUserId);

            if (!IsOwner)
            {
                return(Unauthorized());
            }

            var AllBelongedCat = household.Categories;

            if (AllBelongedCat.Any())
            {
                DbContext.Categories.RemoveRange(AllBelongedCat);
            }

            DbContext.Households.Remove(household);
            DbContext.SaveChanges();

            return(Ok());
        }