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-05 06:22:19 +00:00
|
|
|
|
public DbSet<QueryWordInfo> Keywords { get; set; }
|
|
|
|
|
|
|
|
|
|
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>()
|
|
|
|
|
.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>()
|
2021-08-05 06:22:19 +00:00
|
|
|
|
.Property(e => e.Enabled)
|
2021-07-12 08:07:16 +00:00
|
|
|
|
.HasConversion(
|
2021-07-14 06:13:19 +00:00
|
|
|
|
v => JsonSerializer.Serialize(v, null),
|
2021-07-22 21:12:27 +00:00
|
|
|
|
v => JsonSerializer.Deserialize<SearchOutline.ShopsDisabled>(v, null),
|
|
|
|
|
new ValueComparer<SearchOutline.ShopsDisabled>(
|
2021-07-12 08:07:16 +00:00
|
|
|
|
(a, b) => a.Equals(b),
|
|
|
|
|
c => c.GetHashCode(),
|
2021-07-14 06:13:19 +00:00
|
|
|
|
c => c.Copy()
|
|
|
|
|
)
|
|
|
|
|
);
|
2021-08-05 06:22:19 +00:00
|
|
|
|
|
2021-07-14 06:13:19 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|