Implemented groundwork for search configuration.

This commit is contained in:
2021-07-22 16:12:27 -05:00
parent 3129e5e564
commit 2719142538
41 changed files with 1037 additions and 205 deletions

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Props.Models.User;
namespace Props.Shared.Models.User
{
@@ -9,6 +10,9 @@ namespace Props.Shared.Models.User
[Required]
public string ApplicationUserId { get; set; }
[Required]
public virtual ApplicationUser ApplicationUser { get; set; }
public bool EnableSearchHistory { get; set; } = true;
public bool DarkMode { get; set; } = false;
}

View File

@@ -4,30 +4,30 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Props.Models.Search;
using Props.Shared.Models.User;
namespace Props.Models.User
{
public class ApplicationUser : IdentityUser
{
[Required]
public virtual SearchOutline SearchOutline { get; private set; }
public virtual ISet<SearchOutline> SearchOutlines { get; set; }
[Required]
public virtual ResultsPreferences ResultsPreferences { get; private set; }
[Required]
public virtual ApplicationPreferences ApplicationPreferences { get; private set; }
// TODO: Write project system.
public ApplicationUser()
{
SearchOutline = new SearchOutline();
ResultsPreferences = new ResultsPreferences();
ApplicationPreferences = new ApplicationPreferences();
}
public ApplicationUser(SearchOutline searchOutline, ResultsPreferences resultsPreferences, ApplicationPreferences applicationPreferences)
public ApplicationUser(ResultsPreferences resultsPreferences, ApplicationPreferences applicationPreferences)
{
this.SearchOutline = searchOutline;
this.ResultsPreferences = resultsPreferences;
this.ApplicationPreferences = applicationPreferences;
}

View File

@@ -3,18 +3,27 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json;
using Props.Models.User;
namespace Props.Models
{
public class ResultsPreferences
{
public int Id { get; set; }
[Required]
public string ApplicationUserId { get; set; }
[Required]
public virtual ApplicationUser ApplicationUser { get; set; }
[Required]
public IList<Category> Order { get; set; }
[Required]
public string ProfileName { get; set; }
public ResultsPreferences()
{
Order = new List<Category>(Enum.GetValues<Category>().Length);

View File

@@ -1,76 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Props.Shop.Framework;
namespace Props.Models
{
public class SearchOutline
{
public int Id { get; set; }
[Required]
public string ApplicationUserId { get; set; }
public Filters Filters { get; set; }
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; }
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 ShopToggler Copy()
{
ShopToggler copy = new ShopToggler();
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 &&
MaxResults == other.MaxResults &&
Filters.Equals(other.Filters) &&
ShopStates.Equals(other.ShopStates);
}
public override int GetHashCode()
{
return Id;
}
}
}