protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Order>()
            .HasOne(o => o.Courier)
            .WithMany(u => u.CourierOrders)
            .HasForeignKey(o => o.CourierId);

            modelBuilder.Entity <OrderProduct>()
            .HasKey(t => new { t.OrderId, t.ProductId });

            modelBuilder.Entity <OrderProduct>()
            .HasOne(sc => sc.Order)
            .WithMany(s => s.OrderProduct)
            .HasForeignKey(sc => sc.OrderId);

            modelBuilder.Entity <OrderProduct>()
            .HasOne(sc => sc.Product)
            .WithMany(s => s.OrderProduct)
            .HasForeignKey(sc => sc.ProductId);

            RoleMaster rm = new RoleMaster();

            Role[] roles = rm.GetRoles();

            string passwd = "qweqwe";

            User[] uss =
            {
                new User()
                {
                    Id     = 1,
                    Email  = "*****@*****.**",
                    RoleId = roles.FirstOrDefault(i => i.Name == "Администратор").Id,
                    Active = true
                },
                new User()
                {
                    Id     = 2,
                    Email  = "*****@*****.**",
                    RoleId = roles.FirstOrDefault(i => i.Name == "Пользователь").Id,
                    Active = true
                },
                new User()
                {
                    Id     = 3,
                    Email  = "*****@*****.**",
                    RoleId = roles.FirstOrDefault(i => i.Name == "Пользователь").Id,
                    Active = true
                },
                new User()
                {
                    Id     = 4,
                    Email  = "*****@*****.**",
                    RoleId = roles.FirstOrDefault(i => i.Name == "Курьер").Id,
                    Active = true
                },
                new User()
                {
                    Id     = 5,
                    Email  = "*****@*****.**",
                    RoleId = roles.FirstOrDefault(i => i.Name == "Курьер").Id,
                    Active = true
                }
            };

            PasswdHesher <User> hesher = new PasswdHesher <User>();

            for (int i = 0; i < uss.Length; i++)
            {
                hesher.SetHeshContSalt(uss[i], passwd);
            }

            modelBuilder.Entity <Role>().HasData(roles);
            modelBuilder.Entity <User>().HasData(uss);

            base.OnModelCreating(modelBuilder);
        }
Exemple #2
0
 public AccountController(RoleMaster rm, PasswdHesher <IHesh> ph, IRepositoryBuilder rb, IMass sm) : base(rb, rm)
 {
     MailSender = sm;
     PasswdHesh = ph;
 }