Ejemplo n.º 1
0
        public ActionResult EditingPopup_Destroy([DataSourceRequest] DataSourceRequest request, UserAssignedRoles role)
        {
            if (role != null)
            {
                ApplicationUser user = context.Users.Where(u => u.UserName.Equals(role.UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                var Account = new AccountController();
                string NewRole = role.RoleName;
                Account.UserManager.RemoveFromRoleAsync(role.UserId, NewRole);
                context.Users.Remove(user);
                context.SaveChanges();
                context.SaveChangesAsync();
            }
            return Json(ModelState.ToDataSourceResult());

        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public async Task<ActionResult> EditingPopup_Update([DataSourceRequest] DataSourceRequest request, UserAssignedRoles role)
        {
            if (role != null)
            {
                ApplicationUser user = context.Users.Where(u => u.UserName.Equals(role.UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                var oldRole = user.Roles.FirstOrDefault();
                var Account = new AccountController();
                string oldrole = oldRole.Role.Name;
                string NewRole = role.RoleName;
                if (!oldrole.Equals(NewRole))
                {
                    await Account.UserManager.RemoveFromRoleAsync(role.UserId, oldrole);
                    await Account.UserManager.AddToRoleAsync(role.UserId, NewRole);
                    context.SaveChanges();
                    await context.SaveChangesAsync();
                }
            }
            return Json(ModelState.ToDataSourceResult());

        }
Ejemplo n.º 3
0
        public ActionResult Deactivate(UserAssignedRoles model)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            ApplicationUser user = context.Users.Where(u => u.UserName.Equals(model.UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
            user.isActivated = false;

            UserManager.UpdateAsync(user);

            return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());
            
        }