public void UpdateMetadata_PartialData()
        {
            string documentId = "ADOK-1-250";
            ArchiveCase archiveCaseController = new ArchiveCase();
            ArchiveCaseDocumentModel objArchiveCaseDocumentModel = new ArchiveCaseDocumentModel
            {
                Authority = "Utvalg",
                Category = "Dom",
                ContradictionId = "d571d19a-8242-4608-8186-6799627865ba",
                DecisionId = "",
                DocumentStatus = "",
                Origin = "Utvalg",
                OwnerId = "",
                PartyId = ""
            };

            archiveCaseController.UpdateCaseDocumentMetadata(documentId, objArchiveCaseDocumentModel, _objArchiveModel);
        }
 public void UpdateMetadata_NoDocumentId()
 {
     string documentId = string.Empty;
     ArchiveCase archiveCaseController = new ArchiveCase();
     ArchiveCaseDocumentModel objArchiveCaseDocumentModel = new ArchiveCaseDocumentModel
     {
         Authority = "Utvalg",
         Category = "Dom",
         ContradictionId = "d571d19a-8242-4608-8186-6799627865ba",
         DecisionId = "",
         DocumentStatus = "",
         Origin = "Utvalg",
         OwnerId = "",
         PartyId = ""
     };
     var result = JObject.Parse(archiveCaseController.UpdateCaseDocumentMetadata(documentId, objArchiveCaseDocumentModel, _objArchiveModel));
     Assert.AreEqual("Document ID not found.", result["response"]);
 }
        public string UpdateCaseDocumentMetadata(string documentId, ArchiveCaseDocumentModel fileMetadataObj, ArchiveCredentialModel archiveModel)
        {
            if (archiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                archiveModel.BaseSiteUrl += KeywordApi;
            else
                archiveModel.BaseSiteUrl += "/" + KeywordApi;

            string formDigestValue, libraryName = string.Empty, documentStatusValue = string.Empty;
            RestClient restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

            int localeId = GetLocaleId(restClient);

            if (Equals(localeId, NorwegianNoLocaleId))
            {
                libraryName = DocumentLibraryNo;
                documentStatusValue = DocumentStatusDefaultValNo;
            }
            else if (Equals(localeId, EnglishUsLocaleId))
            {
                libraryName = DocumentLibraryEn;
                documentStatusValue = DocumentStatusDefaultValEn;
            }

            ItemDetailModel listItemDetailObj = GetItemDetailsByDocumentId(documentId, libraryName, restClient);

            //var body = string.Empty;
            //if (listItemDetailObj != null)
            if (!ReferenceEquals(listItemDetailObj, null))
            {
                if (!ReferenceEquals(fileMetadataObj, null))
                {
                    string authority = !string.IsNullOrEmpty(fileMetadataObj.Authority) ? "'Authority':'" + fileMetadataObj.Authority + "'," : string.Empty,
                        //caseNumber = !string.IsNullOrEmpty(Convert.ToString(fileMetadataObj.CaseNumber)) ? "'CaseNumber':'" + fileMetadataObj.CaseNumber + "'," : string.Empty,
                        origin = !string.IsNullOrEmpty(fileMetadataObj.Origin) ? "'Origin':'" + fileMetadataObj.Origin + "'," : string.Empty,
                        category = !string.IsNullOrEmpty(fileMetadataObj.Category) ? "'PCategory':'" + fileMetadataObj.Category + "'," : string.Empty,
                        contradictionId = !string.IsNullOrEmpty(fileMetadataObj.ContradictionId) ? "'ContradictionID':'" + fileMetadataObj.ContradictionId + "'," : string.Empty,
                        decisionId = !string.IsNullOrEmpty(fileMetadataObj.DecisionId) ? "'DecisionID':'" + fileMetadataObj.DecisionId + "'," : string.Empty,
                        partyId = !string.IsNullOrEmpty(fileMetadataObj.PartyId) ? "'PartyID':'" + fileMetadataObj.PartyId + "'," : string.Empty,
                        ownerId = !string.IsNullOrEmpty(fileMetadataObj.OwnerId) ? "'OwnerID':'" + fileMetadataObj.OwnerId + "'," : string.Empty,
                        documentStatus = !string.IsNullOrEmpty(fileMetadataObj.DocumentStatus) ? "'DocumentStatus':'" + fileMetadataObj.DocumentStatus + "'" : "'DocumentStatus':'" + documentStatusValue + "'";

                    string body = string.Concat(
                        "{",
                        "'__metadata':{'type':'" + listItemDetailObj.ListItemEntityTypeFullName + "'},",
                        authority, origin, category, contradictionId,
                        decisionId, partyId, ownerId, documentStatus,
                        "}");

                    RestRequest request =
                        new RestRequest("web/lists/getbytitle('" + libraryName + "')/items(" + listItemDetailObj.Id + ")", Method.POST)
                        {
                            RequestFormat = DataFormat.Json
                        };
                    request.AddHeader(Accept, AcceptHeaderVal);
                    request.AddHeader(ContentType, AcceptHeaderVal);
                    request.AddHeader(HttpMethod, Method.MERGE.ToString());
                    request.AddHeader(IfMatch, listItemDetailObj.ETag);
                    request.AddHeader(RequestDigest, formDigestValue);
                    request.AddParameter(AcceptHeaderVal, body, ParameterType.RequestBody);
                    IRestResponse response = restClient.Execute(request);

                    return string.IsNullOrEmpty(response.Content)
                        ? "{\"response\":\"Case file metadata updated successfully\"}"
                        : "{\"response\":\"Error- Try again\"}";
                }
                return "{\"response\":\"No Metadata found to update for " + documentId + ".\"}";
            }
            else
            {
                return "{\"response\":\"Document ID not found.\"}";
            }
        }