Filtration/Filtration/Models/ItemFilterBlock.cs

52 lines
1.4 KiB
C#
Raw Normal View History

2015-06-04 18:15:54 +01:00
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Filtration.Enums;
using Filtration.Models.BlockItemBaseTypes;
namespace Filtration.Models
{
internal class ItemFilterBlock
2015-06-04 18:15:54 +01:00
{
public ItemFilterBlock()
2015-06-04 18:15:54 +01:00
{
BlockItems = new ObservableCollection<IItemFilterBlockItem> {new ActionBlockItem(BlockAction.Show)};
2015-06-04 18:15:54 +01:00
}
public string Description { get; set; }
public ItemFilterBlockGroup BlockGroup { get; set; }
2015-06-04 18:15:54 +01:00
public BlockAction Action
{
get
{
var actionBlock = BlockItems.OfType<ActionBlockItem>().First();
return actionBlock.Action;
}
set
{
var actionBlock = BlockItems.OfType<ActionBlockItem>().First();
actionBlock.Action = value;
}
}
public ObservableCollection<IItemFilterBlockItem> BlockItems { get; private set; }
2015-06-04 18:15:54 +01:00
public int BlockCount(Type type)
{
return BlockItems != null ? BlockItems.Count(b => b.GetType() == type) : 0;
}
public bool AddBlockItemAllowed(Type type)
{
var blockItem = (IItemFilterBlockItem)Activator.CreateInstance(type);
2015-06-04 18:15:54 +01:00
return BlockCount(type) < blockItem.MaximumAllowed;
}
2015-06-06 20:44:38 +01:00
public bool HasBlockItemOfType<T>()
{
return BlockItems.Count(b => b is T) > 0;
}
2015-06-04 18:15:54 +01:00
}
}