Example #1
0
        public ActionResult AddRole(AspNetRole role)
        {
            FoodSaleAuthEntities context = new FoodSaleAuthEntities();

            context.AspNetRoles.Add(role);
            context.SaveChanges();
            return(View());
        }
Example #2
0
        public ActionResult AddUserToRole(string userName, string roleName)
        {
            FoodSaleAuthEntities context = new FoodSaleAuthEntities();
            AspNetUser           user    = context.AspNetUsers
                                           .Where(u => u.UserName == userName).FirstOrDefault();
            AspNetRole role = context.AspNetRoles
                              .Where(r => r.Name == roleName).FirstOrDefault();

            user.AspNetRoles.Add(role);
            context.SaveChanges();
            return(View());
        }
Example #3
0
        string GetUserRole(Login login)
        {
            FoodSaleAuthEntities context = new FoodSaleAuthEntities();
            var user = context.AspNetUsers.Where(u => u.UserName == login.UserName).FirstOrDefault();
            IQueryable <string> roleQuery = from u in context.AspNetUsers
                                            from r in u.AspNetRoles
                                            where u.UserName == login.UserName
                                            select r.Name;

            string[] roles = roleQuery.ToArray();
            if (roles != null)
            {
                return(roles[0]);
            }
            else
            {
                return(null);
            }
        }