96 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			96 lines
		
	
	
		
			2.5 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; }
 | |
| 
 | |
|         [Required]
 | |
|         public string Name { get; set; } = "Default";
 | |
| 
 | |
|         public Filters Filters { get; set; } = new Filters();
 | |
| 
 | |
|         [Required]
 | |
|         public ShopsDisabled Enabled { 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) &&
 | |
|                 Enabled.Equals(other.Enabled);
 | |
|         }
 | |
| 
 | |
|         public override int GetHashCode()
 | |
|         {
 | |
|             return HashCode.Combine(Id, Name);
 | |
|         }
 | |
| 
 | |
|         public SearchOutline()
 | |
|         {
 | |
|             this.Name = "Default";
 | |
|             this.Filters = new Filters();
 | |
|             this.Enabled = new ShopsDisabled();
 | |
|         }
 | |
| 
 | |
|         public SearchOutline(string name, Filters filters, ShopsDisabled disabled)
 | |
|         {
 | |
|             this.Name = name;
 | |
|             this.Filters = filters;
 | |
|             this.Enabled = disabled;
 | |
|         }
 | |
|     }
 | |
| } |