示例#1
0
        public ActionResult Index()
        {
            SampleDBEntities1 DbContext = new SampleDBEntities1();
            string            username  = User.Identity.Name;
            string            role      = DbContext.Users.FirstOrDefault(x => x.userName == username).role;

            ViewData["role"] = role;
            return(View());
        }
        public override string[] GetRolesForUser(string username)
        {
            SampleDBEntities1 DbContext = new SampleDBEntities1();

            string role  = DbContext.Users.FirstOrDefault(x => x.userName == username).role.ToString();
            string role2 = Regex.Replace(role, @"\s+", "");

            string[] stringArray = new string[] { role2 };
            return(stringArray);
            //string[] result = { "Manager" };
            //return result;
        }
        public ActionResult Login(User user, string ReturnUrl)
        {
            SampleDBEntities1 DbContext = new SampleDBEntities1();
            User data = DbContext.Users.FirstOrDefault(x => x.userName == user.userName && x.password == user.password);

            if (data != null)
            {
                FormsAuthentication.SetAuthCookie(user.userName, false);
                return(RedirectToAction("Index", "Home"));

                // return Redirect(ReturnUrl);
            }
            else
            {
                ModelState.AddModelError("password", "please enter correct user name or password");
                return(View(user));
            }
        }
示例#4
0
 public CustomerRepository(SampleDBEntities1 ctx)
 {
     this.context = ctx;
 }
示例#5
0
 public ProductRepository(SampleDBEntities1 ctx)
 {
     this.context = ctx;
 }