public IActionResult SaveMetadata([FromQuery] long projectId, [FromBody] SaveMetadataRequest request) { if (request == null) { return(BadRequest()); } var client = GetProjectClient(); var contract = new ProjectMetadataContract { Authors = request.Authors, BiblText = request.BiblText, Copyright = request.Copyright, ManuscriptCountry = request.ManuscriptCountry, ManuscriptExtent = request.ManuscriptExtent, ManuscriptIdno = request.ManuscriptIdno, ManuscriptRepository = request.ManuscriptRepository, ManuscriptSettlement = request.ManuscriptSettlement, NotAfter = request.NotAfter != null ? (DateTime?)new DateTime(request.NotAfter.Value, 1, 1) : null, NotBefore = request.NotBefore != null ? (DateTime?)new DateTime(request.NotBefore.Value, 1, 1) : null, OriginDate = request.OriginDate, PublishDate = request.PublishDate, PublishPlace = request.PublishPlace, PublisherText = request.PublisherText, PublisherEmail = request.PublisherEmail, RelicAbbreviation = request.RelicAbbreviation, SourceAbbreviation = request.SourceAbbreviation, SubTitle = request.SubTitle, Title = request.Title, }; long newResourceVersionId = -1; var unsuccessfulData = new List <string>(); try { newResourceVersionId = client.CreateNewProjectMetadataVersion(projectId, contract); } catch (HttpRequestException) { unsuccessfulData.Add(m_localization.Translate("Metadata", "Admin")); } try { client.SetProjectAuthors(projectId, new IntegerIdListContract { IdList = request.AuthorIdList }); } catch (HttpRequestException) { unsuccessfulData.Add(m_localization.Translate("Authors", "Admin")); } try { client.SetProjectResponsiblePersons(projectId, request.ProjectResponsiblePersonIdList); } catch (HttpRequestException) { unsuccessfulData.Add(m_localization.Translate("ResponsiblePeople", "Admin")); } if (unsuccessfulData.Count > 0) { return(new JsonResult(unsuccessfulData) { StatusCode = (int)HttpStatusCode.BadGateway }); } var response = new SaveMetadataResponse { NewResourceVersionId = newResourceVersionId, LastModificationText = DateTime.Now.ToString(m_localization.GetRequestCulture()), LiteraryOriginalText = LiteraryOriginalTextConverter.GetLiteraryOriginalText(request.ManuscriptCountry, request.ManuscriptSettlement, request.ManuscriptRepository, request.ManuscriptIdno, request.ManuscriptExtent), }; return(Json(response)); }
public IActionResult SaveMetadata([FromQuery] long projectId, [FromBody] SaveMetadataRequest request) { if (request == null) { return(BadRequest()); } using (var client = GetRestClient()) { var contract = new ProjectMetadataContract { BiblText = request.BiblText, Copyright = request.Copyright, ManuscriptCountry = request.ManuscriptCountry, ManuscriptExtent = request.ManuscriptExtent, ManuscriptIdno = request.ManuscriptIdno, ManuscriptRepository = request.ManuscriptRepository, ManuscriptSettlement = request.ManuscriptSettlement, NotAfter = request.NotAfter != null ? (DateTime?)new DateTime(request.NotAfter.Value, 1, 1) : null, NotBefore = request.NotBefore != null ? (DateTime?)new DateTime(request.NotBefore.Value, 1, 1) : null, OriginDate = request.OriginDate, PublishDate = request.PublishDate, PublishPlace = request.PublishPlace, PublisherId = request.PublisherId, RelicAbbreviation = request.RelicAbbreviation, SourceAbbreviation = request.SourceAbbreviation, SubTitle = request.SubTitle, Title = request.Title }; long newResourceVersionId = -1; int unsuccessRequestCount = 0; try { newResourceVersionId = client.CreateNewProjectMetadataVersion(projectId, contract); } catch (HttpRequestException) { unsuccessRequestCount++; } try { client.SetProjectAuthors(projectId, new IntegerIdListContract { IdList = request.AuthorIdList }); } catch (HttpRequestException) { unsuccessRequestCount++; } try { client.SetProjectResponsiblePersons(projectId, new IntegerIdListContract { IdList = request.ResponsiblePersonIdList }); } catch (HttpRequestException) { unsuccessRequestCount++; } try { client.SetProjectLiteraryKinds(projectId, new IntegerIdListContract { IdList = request.LiteraryKindIdList }); } catch (HttpRequestException) { unsuccessRequestCount++; } try { client.SetProjectLiteraryGenres(projectId, new IntegerIdListContract { IdList = request.LiteraryGenreIdList }); } catch (HttpRequestException) { unsuccessRequestCount++; } if (unsuccessRequestCount > 0) { return(StatusCode(StatusCodes.Status500InternalServerError)); } var response = new SaveMetadataResponse { NewResourceVersionId = newResourceVersionId, LastModificationText = DateTime.Now.ToString(CultureInfo.CurrentCulture), LiteraryOriginalText = LiteraryOriginalTextConverter.GetLiteraryOriginalText(request.ManuscriptCountry, request.ManuscriptSettlement, request.ManuscriptRepository, request.ManuscriptIdno, request.ManuscriptExtent), }; return(Json(response)); } }