Exemplo n.º 1
0
        public ActionResult UserRoles(string id)
        {
            var Db    = new ScavengerHuntContext();
            var user  = Db.Users.First(u => u.UserName == id);
            var model = new SelectUserRolesViewModel(user);

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Edit(string id, ManageMessageId?Message = null)
        {
            var Db    = new ScavengerHuntContext();
            var user  = Db.Users.First(u => u.UserName == id);
            var model = new EditUserViewModel(user);

            ViewBag.MessageId = Message;
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(string id)
        {
            var Db   = new ScavengerHuntContext();
            var user = Db.Users.First(u => u.UserName == id);

            Db.Users.Remove(user);
            Db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Delete(string id = null)
        {
            var Db    = new ScavengerHuntContext();
            var user  = Db.Users.First(u => u.UserName == id);
            var model = new EditUserViewModel(user);

            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Index()
        {
            var Db    = new ScavengerHuntContext();
            var users = Db.Users;
            var model = new List <EditUserViewModel>();

            foreach (var user in users)
            {
                var u = new EditUserViewModel(user);
                model.Add(u);
            }
            return(View(model));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Edit(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Db   = new ScavengerHuntContext();
                var user = Db.Users.First(u => u.UserName == model.UserName);
                Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                await Db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 7
0
 public ActionResult UserRoles(SelectUserRolesViewModel model)
 {
     if (ModelState.IsValid)
     {
         var idManager = new IdentityManager();
         var Db        = new ScavengerHuntContext();
         var user      = Db.Users.First(u => u.UserName == model.UserName);
         idManager.ClearUserRoles(user.Id);
         foreach (var role in model.Roles)
         {
             if (role.Selected)
             {
                 idManager.AddUserToRole(user.Id, role.RoleName);
             }
         }
         return(RedirectToAction("index"));
     }
     return(View());
 }
Exemplo n.º 8
0
 public Repository(ScavengerHuntContext context)
 {
     _context = context;
 }
Exemplo n.º 9
0
        // Enable initialization with an instance of ApplicationUser:
        public SelectUserRolesViewModel(ApplicationUser user)
            : this()
        {
            this.UserName = user.UserName;

            var Db = new ScavengerHuntContext();

            // Add all available roles to the list of EditorViewModels:
            var allRoles = Db.Roles;
            foreach (var role in allRoles)
            {
                // An EditorViewModel will be used by Editor Template:
                var rvm = new SelectRoleEditorViewModel(role);
                this.Roles.Add(rvm);
            }

            // Set the Selected property to true for those roles for
            // which the current user is a member:
            foreach (var userRole in user.Roles)
            {
                var checkUserRole =
                    this.Roles.Find(r => r.RoleName == userRole.Role.Name);
                checkUserRole.Selected = true;
            }
        }
Exemplo n.º 10
0
 public ActionResult UserRoles(string id)
 {
     var Db = new ScavengerHuntContext();
     var user = Db.Users.First(u => u.UserName == id);
     var model = new SelectUserRolesViewModel(user);
     return View(model);
 }
Exemplo n.º 11
0
 public ActionResult UserRoles(SelectUserRolesViewModel model)
 {
     if (ModelState.IsValid)
     {
         var idManager = new IdentityManager();
         var Db = new ScavengerHuntContext();
         var user = Db.Users.First(u => u.UserName == model.UserName);
         idManager.ClearUserRoles(user.Id);
         foreach (var role in model.Roles)
         {
             if (role.Selected)
             {
                 idManager.AddUserToRole(user.Id, role.RoleName);
             }
         }
         return RedirectToAction("index");
     }
     return View();
 }
Exemplo n.º 12
0
 public ActionResult DeleteConfirmed(string id)
 {
     var Db = new ScavengerHuntContext();
     var user = Db.Users.First(u => u.UserName == id);
     Db.Users.Remove(user);
     Db.SaveChanges();
     return RedirectToAction("Index");
 }
Exemplo n.º 13
0
 public ActionResult Delete(string id = null)
 {
     var Db = new ScavengerHuntContext();
     var user = Db.Users.First(u => u.UserName == id);
     var model = new EditUserViewModel(user);
     if (user == null)
     {
         return HttpNotFound();
     }
     return View(model);
 }
Exemplo n.º 14
0
        public async Task<ActionResult> Edit(EditUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var Db = new ScavengerHuntContext();
                var user = Db.Users.First(u => u.UserName == model.UserName);
                Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                await Db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 15
0
 public ActionResult Edit(string id, ManageMessageId? Message = null)
 {
     var Db = new ScavengerHuntContext();
     var user = Db.Users.First(u => u.UserName == id);
     var model = new EditUserViewModel(user);
     ViewBag.MessageId = Message;
     return View(model);
 }
Exemplo n.º 16
0
 public ActionResult Index()
 {
     var Db = new ScavengerHuntContext();
     var users = Db.Users;
     var model = new List<EditUserViewModel>();
     foreach (var user in users)
     {
         var u = new EditUserViewModel(user);
         model.Add(u);
     }
     return View(model);
 }