/// <summary> /// Updates the project status. /// </summary> /// <param name="projectListItem">The project list item.</param> /// <param name="status">if set to <c>true</c> project will be archived, otherwise restored.</param> private void UpdateProjectStatus(SPListItem projectListItem, bool status) { if (projectListItem == null) { throw new ArgumentNullException(); } var web = projectListItem.Web; web.AllowUnsafeUpdates = true; try { var action = status ? ArchiveProjectAction : RestoreProjectAction; LogMessage(web, $"Updating project '{projectListItem.ID}' - Action: '{action}'", LogKind.Info); projectListItem[ArchivedColumn] = status; if (projectListItem.Fields.ContainsFieldWithInternalName(TimesheetColumn)) { projectListItem[TimesheetColumn] = !status; } projectListItem.Update(); // when associated lists configured - move to archive all of them SPSecurity.RunWithElevatedPrivileges( () => { using (var elevatedSite = new SPSite(web.Site.ID)) { using (var elevatedWeb = elevatedSite.OpenWeb(web.ID)) { elevatedWeb.AllowUnsafeUpdates = true; if (ConnectionProvider.AllowDatabaseConnections(elevatedWeb)) { var pfeProjectRepository = new ProjectRepository(); pfeProjectRepository.UpdateArchivedStatus(web, projectListItem.ParentList.ID, projectListItem.ID, status); } try { var elevatedProjectList = elevatedWeb.Lists.GetList( projectListItem.ParentList.ID, false); var settings = ListCommands.GetGridGanttSettings(elevatedProjectList); if (settings.AssociatedItems) { var associated = ListCommands.GetAssociatedLists(elevatedProjectList) .Cast <AssociatedListInfo>().ToArray(); UpdateAssociatedLists(elevatedWeb, projectListItem.ID, status, associated); } } finally { elevatedWeb.AllowUnsafeUpdates = false; } } } }); } catch (Exception ex) { LogError(web, ex); throw; } finally { web.AllowUnsafeUpdates = false; } }