public ActionResult SaveProjectAttribute(ProjectAttributeModel viewModel) { ProjectAttribute projectAttribute = (viewModel.Id > 0) ? ProjectAttributeRepository.Get(viewModel.Id) : new ProjectAttribute(); projectAttribute.Attributeid = viewModel.Id; projectAttribute.ProjectId = viewModel.ProjectId; projectAttribute.Attributename = viewModel.Name; projectAttribute.Attributevalue = viewModel.Value == null ? string.Empty : viewModel.Value; if (viewModel.Id == 0) { projectAttribute.Attributeorder = ProjectAttributeRepository.GetNextAttributeOrderNumber(viewModel.ProjectId); } int id = ProjectAttributeRepository.Create(projectAttribute); if (id > 0) { ProjectAdminAppModel model = new ProjectAdminAppModel(); model.ProjectAttributes = ProjectAttributeRepository.GetAll(viewModel.ProjectId); return(JsonSuccess(new { Html = RenderPartialViewToString(this, AppManager.Instance.GetAppUrl(Constants.AppId, "views/_ProjectAttributes.cshtml"), model) })); } else { return(JsonError()); } }
public override WidgetResult Show(IssueDto issue = null) { var filter = IsSessionFilter() || CurrentCard.CardType != ProjectTemplatePageType.Custom && "app/projectAdmin/view".Equals(CurrentCard.Url, StringComparison.InvariantCultureIgnoreCase) ? HttpSessionManager.GetFilter(CurrentCard.Id, IssuesFilter.CreateProjectFilter(CurrentUser.Entity.Id, CurrentProject.Entity.Id)) : CurrentCard.Filter; HttpSessionManager.SetFilter(CurrentCard.Id, filter); int?currentProjectId = 0; HttpSessionManager.Set <List <UserIssuesView> >(null, Constants.ProjectAdminSessionView); // Safety check required because of http://gemini.countersoft.com/project/DEV/21/item/5088 PageSettings pageSettings = null; try { if (CurrentCard.Options.ContainsKey(AppGuid)) { pageSettings = CurrentCard.Options[AppGuid].FromJson <PageSettings>(); if (pageSettings.PageData != null) { currentProjectId = pageSettings.PageData.projectId; } } } catch (Exception ex) {} //If no project is selected, select the first workspace project. if ((!currentProjectId.HasValue || currentProjectId.Value == 0) && filter.Projects.HasValue()) { try { var workspaceProjects = filter.Projects.Split('|'); if (workspaceProjects.Count() > 0) { currentProjectId = Convert.ToInt32(workspaceProjects[0]); } } catch (Exception ex) { } } var viewableProjects = ProjectManager.GetAppViewableProjects(this).ToList(); //If you can't view the selected project, select first from viewable projects if (!viewableProjects.Any(s => s.Entity.Id == currentProjectId.Value)) { currentProjectId = viewableProjects.Count > 0 ? viewableProjects.First().Entity.Id : 0; } UserContext.Project = ProjectManager.Convert(Cache.Projects.Get(currentProjectId.Value)); ProjectAdminAppModel model = BuildModelData(); model.ProjectList = new SelectList(viewableProjects, "Entity.Id", "Entity.Name", currentProjectId.GetValueOrDefault()); if (pageSettings == null) { pageSettings = new PageSettings(); } pageSettings.PageData.projectId = currentProjectId.GetValueOrDefault(); CurrentCard.Options[AppGuid] = pageSettings.ToJson(); return(new WidgetResult() { Success = true, Markup = new WidgetMarkup("views/ProjectAdmin.cshtml", model) }); }
public ProjectAdminAppModel BuildModelData() { ProjectAdminAppModel model = new ProjectAdminAppModel(); model.ProjectAdminAppPermissions = new ProjectAdminAppPermissionModel(); //Permission Logic int id = UserContext.Project.Entity.PermissionId.Value; model.ProjectAdminAppPermissions.PermissionSet = new PermissionSetDto(Cache.Permissions.Get(id)); AddRoles(model.ProjectAdminAppPermissions); GlobalConfigurationWidgetData <ProjectAdminConfigModel> data = GeminiContext.GlobalConfigurationWidgetStore.Get <ProjectAdminConfigModel>(AppGuid); var allProjectGroups = Cache.ProjectGroups.GetAll(); //Exclude selected groups from admin screen List <int> excludeGroups = new List <int>(); List <int> excludeUsersFromGroups = new List <int>(); if (data != null && data.Value != null && data.Value.Data != null) { if (data.Value.Data.ExcludeGroups.Count > 0) { excludeGroups = data.Value.Data.ExcludeGroups; } if (data.Value.Data.ExcludeUserFromGroups.Count > 0) { var excludedProjectGroups = allProjectGroups.Where(g => data.Value.Data.ExcludeUserFromGroups.Contains(g.Id)); foreach (var group in excludedProjectGroups) { excludeUsersFromGroups.AddRange(group.Members. Where(a => (a.ProjectId == UserContext.Project.Entity.Id || a.ProjectId == null) && a.UserId != Countersoft.Gemini.Commons.Constants.AnonymousUserId && a.UserId != Countersoft.Gemini.Commons.Constants.SystemAccountUserId).Select(s => s.UserId)); } } } //exclude following groups excludeGroups.Add(Countersoft.Gemini.Commons.Constants.GlobalGroupEveryone); excludeGroups.Add(Countersoft.Gemini.Commons.Constants.GlobalGroupEveryoneAuthenticated); excludeGroups.Add(Countersoft.Gemini.Commons.Constants.GlobalGroupAdministrators); model.ProjectGroups = new List <ProjectGroupModel>(); var projectGroups = allProjectGroups.Where(g => !excludeGroups.Contains(g.Id)); foreach (var projectGroup in projectGroups) { int myProjects = projectGroup.Members.FindAll(m => m.ProjectId == UserContext.Project.Entity.Id && !excludeUsersFromGroups.Contains(m.UserId)).Count(); ProjectGroupModel projectGroupModel = new ProjectGroupModel(); projectGroupModel.Summary = GetSummary(myProjects); projectGroupModel.ProjectGroup = projectGroup; model.ProjectGroups.Add(projectGroupModel); } model.ProjectAttributes = ProjectAttributeRepository.GetAll(UserContext.Project.Entity.Id); return(model); }