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(); }
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); }
public void UpdateCategory(ShopItemCategory category) { _context.Entry(category).State = EntityState.Modified; _context.SaveChanges(); }
public ShopItemCategory GetCategoryById(Guid id) { ShopItemCategory category = _context.Categories.FirstOrDefault(c => c.Id == id); return(category); }
public ShopItemCategory GetCategoryByName(string name) { ShopItemCategory category = _context.Categories.FirstOrDefault(c => c.Name == name); return(category); }
public List <ShopItem> GetFilteredByCategory(ShopItemCategory category) { List <ShopItem> items = _context.Items.Where(i => i.Categories.Any(c => c.Id == category.Id)).ToList(); return(items); }