2021-07-14 01:13:19 -05:00
|
|
|
|
using System;
|
2021-07-09 21:47:40 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-07-20 19:08:57 -05:00
|
|
|
|
using System.Text;
|
2021-07-12 03:07:16 -05:00
|
|
|
|
using System.Text.Json;
|
2021-07-20 19:08:57 -05:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
2021-07-14 01:13:19 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-07-12 03:07:16 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
2021-07-14 01:13:19 -05:00
|
|
|
|
using Props.Models;
|
2021-07-22 16:12:27 -05:00
|
|
|
|
using Props.Models.Search;
|
2021-07-21 01:58:49 -05:00
|
|
|
|
using Props.Models.User;
|
2021-07-14 01:13:19 -05:00
|
|
|
|
using Props.Shop.Framework;
|
2021-07-09 21:47:40 -05:00
|
|
|
|
|
2021-07-13 00:35:31 -05:00
|
|
|
|
namespace Props.Data
|
2021-07-09 21:47:40 -05:00
|
|
|
|
{
|
2021-07-20 19:08:57 -05:00
|
|
|
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
2021-07-09 21:47:40 -05:00
|
|
|
|
{
|
2021-07-22 16:12:27 -05:00
|
|
|
|
DbSet<SearchOutline> SearchOutlines { get; set; }
|
|
|
|
|
DbSet<ProductListingInfo> TrackedListings { get; set; }
|
2021-07-20 19:08:57 -05:00
|
|
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
|
|
|
|
: base(options)
|
2021-07-09 21:47:40 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
2021-07-12 03:07:16 -05:00
|
|
|
|
|
2021-07-14 01:13:19 -05:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2021-07-12 03:07:16 -05:00
|
|
|
|
base.OnModelCreating(modelBuilder);
|
2021-07-14 01:13:19 -05:00
|
|
|
|
|
2021-07-12 03:07:16 -05:00
|
|
|
|
modelBuilder.Entity<ResultsPreferences>()
|
|
|
|
|
.Property(e => e.Order)
|
|
|
|
|
.HasConversion(
|
2021-07-14 01:13:19 -05:00
|
|
|
|
v => JsonSerializer.Serialize(v, null),
|
|
|
|
|
v => JsonSerializer.Deserialize<List<ResultsPreferences.Category>>(v, null),
|
2021-07-12 03:07:16 -05: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 01:13:19 -05:00
|
|
|
|
c => (IList<ResultsPreferences.Category>)c.ToList()
|
2021-07-12 03:07:16 -05:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<SearchOutline>()
|
2021-07-22 16:12:27 -05:00
|
|
|
|
.Property(e => e.Disabled)
|
2021-07-12 03:07:16 -05:00
|
|
|
|
.HasConversion(
|
2021-07-14 01:13:19 -05:00
|
|
|
|
v => JsonSerializer.Serialize(v, null),
|
2021-07-22 16:12:27 -05:00
|
|
|
|
v => JsonSerializer.Deserialize<SearchOutline.ShopsDisabled>(v, null),
|
|
|
|
|
new ValueComparer<SearchOutline.ShopsDisabled>(
|
2021-07-12 03:07:16 -05:00
|
|
|
|
(a, b) => a.Equals(b),
|
|
|
|
|
c => c.GetHashCode(),
|
2021-07-14 01:13:19 -05: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 03:07:16 -05:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-07-09 21:47:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|