public IHttpActionResult UpdatePerformanceMeasureProjectReporting(string apiKey, [FromBody] PerformanceMeasureProjectReportingDto performanceMeasureDto) { Check.Require(apiKey == FirmaWebApiConfiguration.PsInfoApiKey, "Unrecognized api key!"); var performanceMeasure = _databaseEntities.PerformanceMeasures.SingleOrDefault(x => x.PerformanceMeasureID == performanceMeasureDto.PerformanceMeasureID); if (performanceMeasure == null) { var message = $"Performance Measure with ID = {performanceMeasureDto.PerformanceMeasureID} not found"; return(NotFound()); } performanceMeasure.ProjectReporting = performanceMeasureDto.ProjectReporting; _databaseEntities.SaveChangesWithNoAuditing(Tenant.ActionAgendaForPugetSound.TenantID); var performanceMeasureReloaded = new PerformanceMeasureSimpleDto(performanceMeasure); return(Ok(performanceMeasureReloaded)); }
public IHttpActionResult UpdatePerformanceMeasureImportance(string apiKey, [FromBody] PerformanceMeasureImportanceDto performanceMeasureDto) { Check.Require(apiKey == FirmaWebApiConfiguration.PsInfoApiKey, "Unrecognized api key!"); var performanceMeasure = _databaseEntities.PerformanceMeasures.SingleOrDefault(x => x.PerformanceMeasureID == performanceMeasureDto.PerformanceMeasureID); if (performanceMeasure == null) { var message = $"Performance Measure with ID = {performanceMeasureDto.PerformanceMeasureID} not found"; return(NotFound()); } performanceMeasure.Importance = performanceMeasureDto.Importance; var fileResourceDtos = performanceMeasureDto.FileResources; var fileResourceMimeTypes = fileResourceDtos.ToDictionary(x => new { x.FileResourceGUID, x.FileResourceMimeTypeName }, x => MapFileResourceMimeTypeNameToFileResourceMimeType(x.FileResourceMimeTypeName)); if (fileResourceMimeTypes.Values.Any(x => x == null)) { var errors = fileResourceMimeTypes.Where(x => x.Value == null).Select(x => $"Invalid File Resource Mime Type '{x.Key.FileResourceMimeTypeName}' for '{x.Key.FileResourceGUID}'").ToList(); return(BadRequest(string.Join("\r\n", errors))); } // Remove all of these, too hard to merge nicely _databaseEntities.AllFileResourceDatas.RemoveRange(performanceMeasure.PerformanceMeasureImages.Select(x => x.FileResourceInfo.FileResourceData)); _databaseEntities.AllFileResourceInfos.RemoveRange(performanceMeasure.PerformanceMeasureImages.Select(x => x.FileResourceInfo)); _databaseEntities.AllPerformanceMeasureImages.RemoveRange(performanceMeasure.PerformanceMeasureImages); var peopleDictionary = _databaseEntities.People.ToDictionary(x => x.Email); var performanceMeasureImagesToUpdate = fileResourceDtos.Select(x => { var fileResourceMimeTypeID = fileResourceMimeTypes.Single(y => y.Key.FileResourceGUID == x.FileResourceGUID).Value.FileResourceMimeTypeID; var personID = peopleDictionary.ContainsKey(x.Email) ? peopleDictionary[x.Email].PersonID : 5278; var fileResourceInfo = new FileResourceInfo(fileResourceMimeTypeID, x.OriginalBaseFilename, x.OriginalFileExtension, x.FileResourceGUID, personID, x.CreateDate); fileResourceInfo.FileResourceDatas.Add(new FileResourceData(fileResourceInfo.FileResourceInfoID, x.FileResourceData)); var performanceMeasureImage = new PerformanceMeasureImage(performanceMeasure, fileResourceInfo); return(performanceMeasureImage); }).ToList(); _databaseEntities.SaveChangesWithNoAuditing(Tenant.ActionAgendaForPugetSound.TenantID); var performanceMeasureReloaded = new PerformanceMeasureSimpleDto(performanceMeasure); return(Ok(performanceMeasureReloaded)); }