示例#1
0
 public void AddUser(ManageUserVM user)
 {
     AddUser(new User()
     {
         UPN = user.UPN, DisplayName = user.DisplayName
     });
     AddRoleToUser(new UserRoles()
     {
         UPN = user.UPN, RoleID = user.UserRoles.ID
     });
     if (user.UserClients != null)
     {
         foreach (Client client in user.UserClients)
         {
             AddClientToUser(user.UPN, client.UniqueID);
         }
     }
 }
        public ActionResult ManageUser(ManageUserVM userVM, string roleName, string projects)
        {
            List <Project> oldProjects = projectHelper.ListUserProjects(userVM.UserId).ToList();
            var            oldUser     = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userVM.UserId);

            var user = db.Users.Find(userVM.UserId);

            user.Email       = userVM.Email;
            user.UserName    = userVM.Email;
            user.FirstName   = userVM.FirstName;
            user.LastName    = userVM.LastName;
            user.PhoneNumber = userVM.PhoneNumber;
            user.AvatarPath  = userVM.AvatarPath;

            if (FileUploadValidator.IsWebFriendlyImage(userVM.Avatar))
            {
                var fileName     = FileStamp.MakeUnique(userVM.Avatar.FileName);
                var serverFolder = WebConfigurationManager.AppSettings["DefaultAvatarFolder"];
                userVM.Avatar.SaveAs(Path.Combine(Server.MapPath(serverFolder), fileName));
                user.AvatarPath = $"{serverFolder}{fileName}";
            }

            db.SaveChanges();
            projectHelper.updateUserProjects(userVM.UserId, userVM.ProjectIds);



            if (roleName != null)
            {
                foreach (var role in roleHelper.ListUserRoles(user.Id))
                {
                    roleHelper.RemoveUserFromRole(user.Id, role);
                }
                if (!string.IsNullOrEmpty(roleName))
                {
                    roleHelper.AddUserToRole(user.Id, roleName);
                }
            }
            var newUser = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userVM.UserId);

            historyHelper.CheckUserEdits(oldUser, newUser, oldProjects);
            return(RedirectToAction("Index"));
        }
示例#3
0
        public void UpdateManageUsers(ManageUserVM user)
        {
            UserRoles userRole = new UserRoles()
            {
                UPN = user.UPN, RoleID = user.UserRoles.ID
            };

            AddRoleToUser(userRole);
            DeleteUserClients(user.UPN);
            if (user.UserClients != null)
            {
                if (user.UserClients.Count() > 0)
                {
                    foreach (Client client in user.UserClients)
                    {
                        AddClientToUser(user.UPN, client.UniqueID);
                    }
                }
            }
        }
        public ActionResult ManageUser(string userId)
        {
            var user  = userHelper.getUser(userId);
            var model = new ManageUserVM();

            model.UserId           = user.Id;
            model.FirstName        = user.FirstName;
            model.LastName         = user.LastName;
            model.Email            = user.Email;
            model.PhoneNumber      = user.PhoneNumber;
            model.FullName         = user.FullName;
            model.AvatarPath       = user.AvatarPath;
            model.userRole         = roleHelper.ListUserRoles(userId).FirstOrDefault();
            ViewBag.UserProjects   = new MultiSelectList(projectHelper.ListUserProjects(userId), "Id", "Name");
            ViewBag.ListOfProjects = new MultiSelectList(projectHelper.ListUserNotOnProjects(userId), "Id", "Name");

            //model.FirstName = projectHelper.ListUserProjects(userId).ToList();
            //model.NotUserProjects = projectHelper.ListUserNotOnProjects(userId).ToList();
            ViewBag.RoleName = new SelectList(db.Roles, "Name", "Name", model.userRole);
            return(View(model));
        }