Пример #1
0
        private IActionResult CreateView(string viewName, IEnumerable <MenuItem> menu, string controller, string method, MsgVue msg = null)
        {
            ViewData["Controller"] = controller;
            ViewData["Method"]     = method;

            ViewData["Roles"] = RoleM.GetRoles().Where(i => RoleM.ValidationAllowed(i.Id));
            if (msg != null)
            {
                ViewData["ERROR"] = msg;
            }
            return(GetView(viewName, menu));
        }
Пример #2
0
        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);
        }