예제 #1
0
        public void AddCategory(ShopItemCategory category)
        {
            ShopItemCategory existingCategory = _context.Categories.FirstOrDefault(c => c.Id == category.Id);

            if (existingCategory != null)
            {
                throw new DuplicateCategoryException("Duplicate label id: {id}");
            }
            _context.Categories.Add(category);
            _context.SaveChanges();
        }
예제 #2
0
        public bool RemoveCategory(Guid categoryId)
        {
            ShopItemCategory categoryToRemove = _context.Categories.FirstOrDefault(c => c.Id == categoryId);

            if (categoryToRemove == null)
            {
                return(false);
            }
            _context.Categories.Remove(categoryToRemove);
            _context.SaveChanges();
            return(true);
        }
예제 #3
0
 public void UpdateCategory(ShopItemCategory category)
 {
     _context.Entry(category).State = EntityState.Modified;
     _context.SaveChanges();
 }
예제 #4
0
        public ShopItemCategory GetCategoryById(Guid id)
        {
            ShopItemCategory category = _context.Categories.FirstOrDefault(c => c.Id == id);

            return(category);
        }
예제 #5
0
        public ShopItemCategory GetCategoryByName(string name)
        {
            ShopItemCategory category = _context.Categories.FirstOrDefault(c => c.Name == name);

            return(category);
        }
예제 #6
0
        public List <ShopItem> GetFilteredByCategory(ShopItemCategory category)
        {
            List <ShopItem> items = _context.Items.Where(i => i.Categories.Any(c => c.Id == category.Id)).ToList();

            return(items);
        }