/// <summary> /// Gets a Project for a shortProjectId for TBC /// Regardless of archived state and user role /// </summary> public static async Task <ProjectDetailResponseModel> GetProjectForCustomer(Guid customerUid, Guid?userUid, long projectShortId, ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders) { log.LogDebug($"{nameof(GetProjectForCustomer)} customerUid {customerUid}, userUid {userUid} projectShortId {projectShortId}"); var projects = await cwsProjectClient.GetProjectsForCustomer(customerUid, userUid, type : CwsProjectType.AcceptsTagFiles, customHeaders : customHeaders); var projectMatches = projects.Projects.Where(p => (Guid.TryParse(p.ProjectId, out var g) ? g.ToLegacyId() : 0) == projectShortId).ToList(); log.LogDebug($"{nameof(GetProjectForCustomer)} Found {projectMatches.Count} projects"); if (projectMatches.Count != 1) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, (projectMatches.Count == 0 ? 1 : 139)); } log.LogDebug($"{nameof(GetProjectForCustomer)} Project matched {JsonConvert.SerializeObject(projectMatches[0])}"); return(projectMatches[0]); }
/// <summary> /// Gets a Project list for customer uid. /// Includes all projects, regardless of archived state and user role /// </summary> public static async Task <List <ProjectDatabaseModel> > GetProjectListForCustomer(Guid customerUid, Guid?userUid, ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, CwsProjectType?projectType, ProjectStatus?status, bool onlyAdmin, bool includeBoundaries, IHeaderDictionary customHeaders) { log.LogDebug($"{nameof(GetProjectListForCustomer)} customerUid {customerUid}, userUid {userUid}"); var projects = await cwsProjectClient.GetProjectsForCustomer(customerUid, userUid, includeBoundaries, projectType, status, onlyAdmin, customHeaders); var projectDatabaseModelList = new List <ProjectDatabaseModel>(); if (projects.Projects != null) { foreach (var project in projects.Projects) { var projectDatabaseModel = ConvertCwsToWorksOSProject(project, log); if (projectDatabaseModel != null) { projectDatabaseModelList.Add(projectDatabaseModel); } } } log.LogDebug($"{nameof(GetProjectListForCustomer)} Project list contains {projectDatabaseModelList.Count} projects"); return(projectDatabaseModelList); }