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
|
|
|
|
|
{
|
2015-06-08 20:17:34 +01:00
|
|
|
|
internal class ItemFilterBlock
|
2015-06-04 18:15:54 +01:00
|
|
|
|
{
|
2015-06-08 20:17:34 +01:00
|
|
|
|
public ItemFilterBlock()
|
2015-06-04 18:15:54 +01:00
|
|
|
|
{
|
2015-06-08 20:17:34 +01:00
|
|
|
|
BlockItems = new ObservableCollection<IItemFilterBlockItem> {new ActionBlockItem(BlockAction.Show)};
|
2015-06-04 18:15:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Description { get; set; }
|
2015-06-08 22:29:39 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 20:17:34 +01:00
|
|
|
|
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)
|
|
|
|
|
{
|
2015-06-08 20:17:34 +01:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|