public ActionResult UserAllocation() { var model = new ServerConfigViewModel() { Users = db.Users.ToList(), Projects = db.Projects.ToList() }; return(View(model)); }
public ServerConfigPage(Session session) { InitializeComponent(); BindingContext = viewModel = new ServerConfigViewModel() { ServerUri = session.ServerUri }; }
public HttpResponseMessage ServerClient(HttpRequestMessage request, ServerConfigViewModel serverVM) { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { bool checkData = serverConfigService.ServerClient(serverVM.ServerName, serverVM.UserName, serverVM.Password, serverVM.Database, serverVM.Option); response = request.CreateResponse(HttpStatusCode.Created, checkData); } return(response); }
public ActionResult AddUsersToProject(AddRemoveUsersProjectsModel model) { var projectHelper = new ProjectHelper(db); var errors = new List <string>(); var successes = new List <string>(); if (model.UserIds == null) { errors.Add("You must select at least 1 user to manipulate."); } else if (model.ProjectIds == null) { errors.Add("You must select at least 1 project."); } else { foreach (string userId in model.UserIds) { var user = db.Users.FirstOrDefault(u => u.Id == userId); if (user != null) { foreach (int projectId in model.ProjectIds) { var addProjectSuccess = projectHelper.AddUserToProject(userId, projectId); if (!addProjectSuccess) { errors.Add($"Unable to add '{user.FullNameStandard}' to project '{db.Projects.Find( projectId ).Name}'."); } else { successes.Add($"'{user.FullNameStandard}' has been added to the '{db.Projects.Find( projectId ).Name}' project."); } } } else //user ID was not found. { if (!errors.Contains("Unable to locate one or more selected users.")) { errors.Add("Unable to locate one or more selected users."); } } } } if (errors.Count > 0) { foreach (var err in errors) { TempData.AddDangerToast(err); } } if (successes.Count > 0) { foreach (var msg in successes) { TempData.AddSuccessToast(msg); } } ServerConfigViewModel viewModel = new ServerConfigViewModel() { Users = db.Users.ToList(), Projects = db.Projects.ToList(), Workflows = db.ProjectWorkflows.ToList() }; return(View(viewName: model.ReturningViewName ?? null, model: viewModel)); }
public ActionResult SetProjectWorkflow(SetProjectWorkflowModel model) { var projectHelper = new ProjectHelper(db); var errors = new List <string>(); var successes = new List <string>(); if (model.ProjectIds == null) { errors.Add("You must select at least 1 project to set the workflow of."); } else if (model.WorkflowId == null) { errors.Add("You must select at least 1 workflow to assign."); } else { var workflow = db.ProjectWorkflows.FirstOrDefault(pwf => pwf.Id == model.WorkflowId); if (workflow == null) { errors.Add("Unable to locate the selected workflow."); } else { foreach (int projectId in model.ProjectIds) { var project = db.Projects.FirstOrDefault(p => p.Id == projectId); if (project != null) { var result = projectHelper.SetProjectWorkflow(projectId, workflow.Id, db); if (!result) { errors.Add($"Unable to change the workflow of project '{project.Name}' to '{workflow.Name}'."); } else { successes.Add($"{project.Name}'s workflow has been changed to {workflow.Name}"); } } else //project ID was not found. { errors.Add("Unable to locate one of the selected projects."); } } } } db.SaveChanges(); if (errors.Count > 0) { foreach (var err in errors) { TempData.AddDangerToast(err); } } if (successes.Count > 0) { foreach (var msg in successes) { TempData.AddSuccessToast(msg); } } var viewModel = new ServerConfigViewModel() { Users = db.Users.ToList(), Projects = db.Projects.ToList(), Workflows = db.ProjectWorkflows.ToList() }; return(View(viewModel)); }
public ActionResult RemoveUsersFromRoles(AddRemoveUsersRolesModel model) { var roleHelper = new PermissionsHelper(db); var roleDisplays = new RoleDisplayDictionary(); var errors = new List <string>(); var successes = new List <string>(); if (model.UserIds == null) { errors.Add("You must select at least 1 user to manipulate."); } else if (model.Roles == null) { errors.Add("You must select at least 1 role."); } else { foreach (string userId in model.UserIds) { var user = db.Users.FirstOrDefault(u => u.Id == userId); if (user != null) { foreach (string role in model.Roles) { var removeRoleSuccess = roleHelper.RemoveUserFromRole(user.Id, role); if (!removeRoleSuccess) { errors.Add($"Unable to remove '{user.FullNameStandard}' from the role '{roleDisplays[role]}'. Is the user in this role?"); } else { successes.Add($"'{user.FullNameStandard}' has been removed from the '{roleDisplays[role]}' role."); } } } else //user ID was not found. { if (!errors.Contains("Unable to locate one of the selected users.")) { errors.Add("Unable to locate one of the selected users."); } } } } if (errors.Count > 0) { foreach (var err in errors) { TempData.AddDangerToast(err); } } if (successes.Count > 0) { foreach (var msg in successes) { TempData.AddSuccessToast(msg); } } ServerConfigViewModel viewModel = new ServerConfigViewModel() { Users = db.Users.ToList(), Projects = db.Projects.ToList(), Workflows = db.ProjectWorkflows.ToList() }; return(View(viewModel)); }
public ServerConfigPage() { InitializeComponent(); BindingContext = viewModel = new ServerConfigViewModel(); }