public SelectListItem BuildCategoryOption(Category category)
 {
     return new SelectListItem
     {
         Value = category.Id.ToString(),
         Text = string.Join(CategoryPathSeparator,
             category.GetCategoryPath()
             .Select(x => x.Name)
             .Concat(new[] {category.Name}))
     };
 }
        public void Update(Category model)
        {
            if (model.ParentCategoryId == model.Id)
            {
                throw new InvalidOperationException("A category cannot be its own parent");
            }

            if (model.ParentCategoryId.HasValue &&
                // ReSharper disable once PossibleInvalidOperationException
                model.GetCategoryPath().Any(x => x.Id == model.ParentCategoryId.Value))
            {
                throw new InvalidOperationException("Cannot set the parent category to a child category");
            }

            _catalogContext.Entry(model).State = EntityState.Modified;
        }