1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using Karsha_Site.Application.Interfaces.Contexts;
- using Karsha_Site.Domain.Entinies.Products;
- using Karsha_Site.Domain.Entinies.Customers;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Karsha_Site.Domain.Entities.Products;
- using Karsha_Site.Domain.Entities.About;
- using System.ComponentModel;
-
- namespace Karsha_Site.Persistance.Contexts
- {
- public class DataBaseContext:DbContext, IDataBaseContext
- {
- public DataBaseContext(DbContextOptions options) : base(options)
- {
- }
- public DbSet<Customer> Customers { get; set; }
- public DbSet<Category> Categories { get; set; }
- public DbSet<Product> Products { get; set; }
- public DbSet<ProductImages> ProductImages { get; set; }
- public DbSet<ProductFeatures> ProductFeatures { get; set; }
- public DbSet<AboutUs> Abouts { get; set; }
- public DbSet<AboutAddress> AboutAddress { get; set; }
- public DbSet<AboutTels> AboutTels { get; set; }
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
-
- //افزودن مقادیر پیشفرض به جدول Roles
- //modelBuilder.Entity<Role>().HasData(new Role { Id = 1, Name = nameof(UserRoles.Admin) });
- //modelBuilder.Entity<Role>().HasData(new Role { Id = 2, Name = nameof(UserRoles.Operator) });
- //modelBuilder.Entity<Role>().HasData(new Role { Id = 3, Name = nameof(UserRoles.Customer) });
-
-
- //// اعمال ایندکس بر روی فیلد ایمیل
- //// اعمال عدم تکراری بودن ایمیل
- //modelBuilder.Entity<User>().HasIndex(u => u.Email).IsUnique();
-
-
- //--
-
- modelBuilder.Entity<Customer>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<Category>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<AboutUs>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<AboutAddress>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<AboutTels>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<Product>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<ProductFeatures>().HasQueryFilter(p => !p.IsRemoved);
- modelBuilder.Entity<ProductImages>().HasQueryFilter(p => !p.IsRemoved);
-
-
-
- }
- }
- }
|