public UsuariosController() { context = GetContext(); _repo = new UserRepository(); }
public CursosController() { _db = new ColegioTerciarioContext(); }
public ActionResult Edit(EditUserViewModel vm, params string[] selectedRoles) { ViewBag.ALUMNOS = new SelectList(new PersonasRepository().GetAlumnos(), "ID", "PERSONA_NOMBRE_COMPLETO"); var userRoles = UserManager.GetRoles(vm.ID); ViewBag.USER_ROLES = RoleManager.Roles.ToList().Select(x => new SelectListItem() { Selected = userRoles.Contains(x.Name), Text = x.Name, Value = x.Name }); if (ModelState.IsValid) { var db = new ColegioTerciarioContext(); var usuario = db.Users.Find(vm.ID); usuario.USER_PERSONA_ID = vm.USER_PERSONA_ID; usuario.UserName = vm.UserName; if (usuario.Email != vm.Email) { usuario.Email = vm.Email; }; var roleStore = new RoleStore<IdentityRole>(context); var roleManager = new RoleManager<IdentityRole>(roleStore); if (vm.USER_ROLES != null) { var rolesToDelete = (from r in roleManager.Roles where !vm.USER_ROLES.Contains(r.Name) select r.Name).ToArray(); var removeFromRoles = UserManager.RemoveFromRoles(vm.ID, rolesToDelete); foreach (var role in vm.USER_ROLES) { if (!UserManager.GetRoles(vm.ID).Contains(role)) { var addtorole = UserManager.AddToRole(vm.ID, role); } } } else { UserManager.RemoveFromRoles(vm.ID, roleManager.Roles.Select(r => r.Name).ToArray()); } db.SaveChanges(); if (vm.Password != null) { UserManager.RemovePassword(usuario.Id); var result = UserManager.AddPassword(usuario.Id, vm.Password); if (result.Succeeded) { return RedirectToAction("Index"); } AddErrors(result); return View(vm); } return RedirectToAction("Index"); } else { return View(vm); } }
public PersonasController() { _db = new ColegioTerciarioContext(); _repo = new PersonasRepository(); }
public AdminController() { _db = new ColegioTerciarioContext(); }
public MateriasXCursoRepository(ColegioTerciarioContext dbContext) { this.dbContext = dbContext; }
public RolesController() { context = GetContext(); }
public UserRepository() { context = new ColegioTerciarioContext(); store = new UserStore<ApplicationUser>(context); manager = new UserManager<ApplicationUser>(store); }