using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using Props.Models.User; using Props.Shop.Framework; namespace Props.Models.Search { public class SearchOutline { public int Id { get; set; } public int SearchOutlinePreferencesId { get; set; } [Required] public virtual SearchOutlinePreferences SearchOutlinePreferences { get; set; } [Required] public string Name { get; set; } public Filters Filters { get; set; } [Required] public ShopSelector DisabledShops { get; set; } public sealed class ShopSelector : HashSet { public bool this[string name] { get { return this.Contains(name); } set { if (value) { this.Add(name); } else { this.Remove(name); } } } public ShopSelector() { } public ShopSelector(IEnumerable disabledShops) : base(disabledShops) { } } public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return false; } SearchOutline other = (SearchOutline)obj; return Id == other.Id && Name.Equals(other.Name) && Filters.Equals(other.Filters) && DisabledShops.Equals(other.DisabledShops); } public override int GetHashCode() { return HashCode.Combine(Id, Name, Filters, DisabledShops); } public SearchOutline() { this.Filters = new Filters(); this.DisabledShops = new ShopSelector(); } public SearchOutline(string name, Filters filters, ShopSelector disabled) { this.Name = name; this.Filters = filters; this.DisabledShops = disabled; } } }