2021-07-14 06:13:19 +00:00
|
|
|
|
using System;
|
2021-07-10 02:47:40 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-07-12 08:07:16 +00:00
|
|
|
|
using System.Text.Json;
|
2021-07-14 06:13:19 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using IdentityServer4.EntityFramework.Options;
|
|
|
|
|
using Microsoft.AspNetCore.ApiAuthorization.IdentityServer;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-07-12 08:07:16 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
2021-07-14 06:13:19 +00:00
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Props.Models;
|
|
|
|
|
using Props.Shared.Models;
|
|
|
|
|
using Props.Shop.Framework;
|
2021-07-10 02:47:40 +00:00
|
|
|
|
|
2021-07-13 05:35:31 +00:00
|
|
|
|
namespace Props.Data
|
2021-07-10 02:47:40 +00:00
|
|
|
|
{
|
|
|
|
|
public class ApplicationDbContext : ApiAuthorizationDbContext<ApplicationUser>
|
|
|
|
|
{
|
|
|
|
|
public ApplicationDbContext(
|
|
|
|
|
DbContextOptions options,
|
|
|
|
|
IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options, operationalStoreOptions)
|
|
|
|
|
{
|
|
|
|
|
}
|
2021-07-12 08:07:16 +00:00
|
|
|
|
|
2021-07-14 06:13:19 +00:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2021-07-12 08:07:16 +00:00
|
|
|
|
base.OnModelCreating(modelBuilder);
|
2021-07-14 06:13:19 +00:00
|
|
|
|
|
2021-07-12 08:07:16 +00:00
|
|
|
|
modelBuilder.Entity<ResultsPreferences>()
|
|
|
|
|
.Property(e => e.Order)
|
|
|
|
|
.HasConversion(
|
2021-07-14 06:13:19 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, null),
|
|
|
|
|
v => JsonSerializer.Deserialize<List<ResultsPreferences.Category>>(v, null),
|
2021-07-12 08:07:16 +00:00
|
|
|
|
new ValueComparer<IList<ResultsPreferences.Category>>(
|
|
|
|
|
(a, b) => a.SequenceEqual(b),
|
|
|
|
|
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
|
2021-07-14 06:13:19 +00:00
|
|
|
|
c => (IList<ResultsPreferences.Category>)c.ToList()
|
2021-07-12 08:07:16 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<SearchOutline>()
|
|
|
|
|
.Property(e => e.ShopStates)
|
|
|
|
|
.HasConversion(
|
2021-07-14 06:13:19 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, null),
|
2021-07-12 08:07:16 +00:00
|
|
|
|
v => JsonSerializer.Deserialize<SearchOutline.ShopToggler>(v, null),
|
|
|
|
|
new ValueComparer<SearchOutline.ShopToggler>(
|
|
|
|
|
(a, b) => a.Equals(b),
|
|
|
|
|
c => c.GetHashCode(),
|
2021-07-14 06:13:19 +00:00
|
|
|
|
c => c.Copy()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
modelBuilder.Entity<SearchOutline>()
|
|
|
|
|
.Property(e => e.Filters)
|
|
|
|
|
.HasConversion(
|
|
|
|
|
v => JsonSerializer.Serialize(v, null),
|
|
|
|
|
v => JsonSerializer.Deserialize<Filters>(v, null),
|
|
|
|
|
new ValueComparer<Filters>(
|
|
|
|
|
(a, b) => a.Equals(b),
|
|
|
|
|
c => c.GetHashCode(),
|
|
|
|
|
c => c.Copy()
|
2021-07-12 08:07:16 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-07-10 02:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|