79 lines
2.0 KiB
C#
79 lines
2.0 KiB
C#
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; }
|
|
|
|
[Required]
|
|
public string ApplicationUserId { get; set; }
|
|
|
|
[Required]
|
|
public virtual ApplicationUser ApplicationUser { get; set; }
|
|
|
|
public Filters Filters { get; set; } = new Filters();
|
|
|
|
[Required]
|
|
public ShopsDisabled Disabled { get; set; } = new ShopsDisabled();
|
|
|
|
public sealed class ShopsDisabled : HashSet<string>
|
|
{
|
|
public int TotalShops { get; set; }
|
|
public bool this[string name]
|
|
{
|
|
get
|
|
{
|
|
return !this.Contains(name);
|
|
}
|
|
set
|
|
{
|
|
if (value == false && TotalShops - Count <= 1) return;
|
|
if (value)
|
|
{
|
|
this.Remove(name);
|
|
}
|
|
else
|
|
{
|
|
this.Add(name);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ShopsDisabled Copy()
|
|
{
|
|
ShopsDisabled copy = new ShopsDisabled();
|
|
copy.Union(this);
|
|
return copy;
|
|
}
|
|
|
|
public bool IsShopToggleable(string shop)
|
|
{
|
|
return (!Contains(shop) && TotalShops - Count > 1) || Contains(shop);
|
|
}
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj == null || GetType() != obj.GetType())
|
|
{
|
|
return false;
|
|
}
|
|
SearchOutline other = (SearchOutline)obj;
|
|
return
|
|
Id == other.Id &&
|
|
Filters.Equals(other.Filters) &&
|
|
Disabled.Equals(other.Disabled);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Id;
|
|
}
|
|
}
|
|
} |