コード例 #1
0
 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}))
     };
 }
コード例 #2
0
        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;
        }
コード例 #3
0
 public void Create(Category model)
 {
     _catalogContext.Categories.Add(model);
 }