2021-07-12 08:07:16 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
2021-07-13 05:35:31 +00:00
|
|
|
using Props.Shop.Framework;
|
2021-07-12 08:07:16 +00:00
|
|
|
|
2021-07-13 05:35:31 +00:00
|
|
|
namespace Props.Models
|
2021-07-12 08:07:16 +00:00
|
|
|
{
|
|
|
|
public class SearchOutline
|
|
|
|
{
|
|
|
|
public int Id { get; set; }
|
2021-07-14 06:13:19 +00:00
|
|
|
[Required]
|
2021-07-12 08:07:16 +00:00
|
|
|
public string ApplicationUserId { get; set; }
|
|
|
|
|
2021-07-14 06:13:19 +00:00
|
|
|
public Filters Filters { get; set; }
|
2021-07-12 08:07:16 +00:00
|
|
|
public int MaxResults { get; set; } = 100;
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
public ShopToggler ShopStates { get; set; } = new ShopToggler();
|
|
|
|
|
|
|
|
public sealed class ShopToggler : HashSet<string>
|
|
|
|
{
|
|
|
|
public int TotalShops { get; set; }
|
2021-07-14 06:13:19 +00:00
|
|
|
public bool this[string name]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2021-07-12 08:07:16 +00:00
|
|
|
return !this.Contains(name);
|
|
|
|
}
|
2021-07-14 06:13:19 +00:00
|
|
|
set
|
|
|
|
{
|
2021-07-12 08:07:16 +00:00
|
|
|
if (value == false && TotalShops - Count <= 1) return;
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
this.Remove(name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.Add(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-14 06:13:19 +00:00
|
|
|
public ShopToggler Copy()
|
|
|
|
{
|
|
|
|
ShopToggler copy = new ShopToggler();
|
|
|
|
copy.Union(this);
|
|
|
|
return copy;
|
2021-07-12 08:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-07-14 06:13:19 +00:00
|
|
|
SearchOutline other = (SearchOutline)obj;
|
|
|
|
return
|
|
|
|
Id == other.Id &&
|
|
|
|
MaxResults == other.MaxResults &&
|
|
|
|
Filters.Equals(other.Filters) &&
|
2021-07-12 08:07:16 +00:00
|
|
|
ShopStates.Equals(other.ShopStates);
|
|
|
|
}
|
2021-07-14 06:13:19 +00:00
|
|
|
|
2021-07-12 08:07:16 +00:00
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|