Пример #1
0
        public override void CreateRole(string roleName)
        {
            Role newRole = new Role()
            {
                Name = roleName
            };
            ManageContext db = new ManageContext();

            db.Roles.Add(newRole);
            db.SaveChanges();
        }
Пример #2
0
    public Contexts()
    {
        game   = new GameContext();
        global = new GlobalContext();
        input  = new InputContext();
        manage = new ManageContext();

        var postConstructors = System.Linq.Enumerable.Where(
            GetType().GetMethods(),
            method => System.Attribute.IsDefined(method, typeof(Entitas.CodeGeneration.Attributes.PostConstructorAttribute))
            );

        foreach (var postConstructor in postConstructors)
        {
            postConstructor.Invoke(this, null);
        }
    }
Пример #3
0
 private void tsbQueryPO_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     try
     {
         using (var db = new ManageContext())
         {
             var q = db.xm_plug_v_POList.ToList();
             dataGridView1.DataSource = q;
             Utility.Style.StyleDataGridView styleDataGridView = new Utility.Style.StyleDataGridView();
             this.Cursor = Cursors.Default;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + ex.InnerException, "订单查询出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #4
0
 public override string[] GetRolesForUser(string Login)
 {
     string[] role = new string[] { };
     using (ManageContext db = new ManageContext())
     {
         // Получаем пользователя
         Employee Employee = db.Employees.FirstOrDefault(u => u.Login == Login);
         if (Employee != null)
         {
             // Получаем роль
             Role userRole = db.Roles.Find(Employee.RoleId);
             if (userRole != null)
             {
                 role = new string[] { userRole.Name };
             }
         }
     }
     return(role);
 }
Пример #5
0
        public override bool IsUserInRole(string Login, string roleName)
        {
            bool outputResult = false;

            // Находим пользователя
            using (ManageContext db = new ManageContext())
            {
                // Получаем пользователя
                Employee Employee = db.Employees.FirstOrDefault(u => u.Login == Login);
                if (Employee != null)
                {
                    // получаем роль
                    Role userRole = db.Roles.Find(Employee.RoleId);
                    //сравниваем
                    if (userRole != null && userRole.Name == roleName)
                    {
                        outputResult = true;
                    }
                }
            }
            return(outputResult);
        }
Пример #6
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                // поиск пользователя в бд
                Employee Employee = null;
                using (ManageContext db = new ManageContext())
                {
                    Employee = db.Employees.FirstOrDefault(u => u.Login == model.Login && u.Password == model.Password);
                }
                if (Employee != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Login, true);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.Message = "Пользователя с таким логином и паролем нет";
                }
            }

            return(View(model));
        }
Пример #7
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                Employee Employee = null;
                using (ManageContext db = new ManageContext())
                {
                    Employee = db.Employees.FirstOrDefault(u => u.Login == model.Login);
                }
                if (Employee == null)
                {
                    // создаем нового пользователя
                    using (ManageContext db = new ManageContext())
                    {
                        db.Employees.Add(new Employee {
                            Login = model.Login, Password = model.Password, Role = db.Roles.Where(i => i.Name == "Admin").FirstOrDefault()
                        });
                        db.SaveChanges();

                        Employee = db.Employees.Where(u => u.Login == model.Login && u.Password == model.Password).FirstOrDefault();
                    }
                    // если пользователь удачно добавлен в бд
                    if (Employee != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }

            return(View(model));
        }
Пример #8
0
 public ManageRepository(ManageContext context)
 {
     _context = context;
 }
Пример #9
0
 public UnitOfWork2(ManageContext flowContext, GwContext opwayContext)
 {
     _flowContext  = flowContext;
     _opwayContext = opwayContext;
 }
Пример #10
0
 public UnitOfWork(ManageContext flowContext)
 {
     _flowContext = flowContext;
 }