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-21 00:08:57 +00:00
|
|
|
|
using System.Text;
|
2021-07-12 08:07:16 +00:00
|
|
|
|
using System.Text.Json;
|
2021-07-21 00:08:57 +00:00
|
|
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
2021-07-14 06:13:19 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-07-12 08:07:16 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
2021-08-05 06:22:19 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
2021-07-14 06:13:19 +00:00
|
|
|
|
using Props.Models;
|
2021-07-22 21:12:27 +00:00
|
|
|
|
using Props.Models.Search;
|
2021-07-21 06:58:49 +00:00
|
|
|
|
using Props.Models.User;
|
2021-07-14 06:13:19 +00:00
|
|
|
|
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
|
|
|
|
{
|
2021-07-21 00:08:57 +00:00
|
|
|
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
2021-07-10 02:47:40 +00:00
|
|
|
|
{
|
2021-08-17 07:59:01 +00:00
|
|
|
|
public DbSet<QueryWordInfo> QueryWords { get; set; }
|
2021-08-05 06:22:19 +00:00
|
|
|
|
|
|
|
|
|
public DbSet<ProductListingInfo> ProductListingInfos { get; set; }
|
|
|
|
|
|
2021-07-21 00:08:57 +00:00
|
|
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
|
|
|
|
: base(options)
|
2021-07-10 02:47:40 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
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>()
|
2021-08-09 18:32:16 +00:00
|
|
|
|
.Property(e => e.Order)
|
|
|
|
|
.HasConversion(
|
2022-01-02 22:20:29 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
|
|
|
|
|
v => JsonSerializer.Deserialize<List<ResultsPreferences.Category>>(v, (JsonSerializerOptions)null),
|
2021-08-09 18:32:16 +00:00
|
|
|
|
new ValueComparer<IList<ResultsPreferences.Category>>(
|
|
|
|
|
(a, b) => a.SequenceEqual(b),
|
|
|
|
|
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
|
|
|
|
|
c => (IList<ResultsPreferences.Category>)c.ToList()
|
|
|
|
|
)
|
|
|
|
|
);
|
2021-07-12 08:07:16 +00:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<SearchOutline>()
|
2021-08-17 07:59:01 +00:00
|
|
|
|
.Property(e => e.DisabledShops)
|
2021-08-09 18:32:16 +00:00
|
|
|
|
.HasConversion(
|
2022-01-02 22:20:29 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
|
|
|
|
|
v => JsonSerializer.Deserialize<SearchOutline.ShopSelector>(v, (JsonSerializerOptions)null),
|
2021-08-17 07:59:01 +00:00
|
|
|
|
new ValueComparer<SearchOutline.ShopSelector>(
|
2021-08-09 18:32:16 +00:00
|
|
|
|
(a, b) => a.Equals(b),
|
|
|
|
|
c => c.GetHashCode(),
|
2021-08-17 07:59:01 +00:00
|
|
|
|
c => new SearchOutline.ShopSelector(c)
|
2021-08-09 18:32:16 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
2021-08-05 06:22:19 +00:00
|
|
|
|
|
2021-07-14 06:13:19 +00:00
|
|
|
|
modelBuilder.Entity<SearchOutline>()
|
2021-08-09 18:32:16 +00:00
|
|
|
|
.Property(e => e.Filters)
|
|
|
|
|
.HasConversion(
|
2022-01-02 22:20:29 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
|
|
|
|
|
v => JsonSerializer.Deserialize<Filters>(v, (JsonSerializerOptions)null),
|
2021-08-09 18:32:16 +00:00
|
|
|
|
new ValueComparer<Filters>(
|
|
|
|
|
(a, b) => a.Equals(b),
|
|
|
|
|
c => c.GetHashCode(),
|
|
|
|
|
c => c.Copy()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ProductListingInfo>()
|
|
|
|
|
.Property(e => e.ProductListing)
|
|
|
|
|
.HasConversion(
|
2022-01-02 22:20:29 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null),
|
|
|
|
|
v => JsonSerializer.Deserialize<ProductListing>(v, (JsonSerializerOptions)null),
|
2021-08-09 18:32:16 +00:00
|
|
|
|
new ValueComparer<ProductListing>(
|
|
|
|
|
(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
|
|
|
|
}
|
|
|
|
|
}
|