コード例 #1
0
 public UnitTest()
 {
     _objArchiveModel = new ArchiveCredentialModel
     {
         BaseSiteUrl = Convert.ToString(ConfigurationManager.AppSettings["BaseSiteUrl"]),
         Username = Convert.ToString(ConfigurationManager.AppSettings["UserName"]),
         Password = Convert.ToString(ConfigurationManager.AppSettings["Password"])
     };
 }
 /// <summary>
 /// Constructor to initialize the resources
 /// </summary>
 /// <remarks>Initializes Interface and Model</remarks>
 /// <param name="objArchiveCase">Interface object</param>
 public ArchiveCaseController(IArchiveCase objArchiveCase) //, ArchiveCredentialModel objArchiveModel
 {
     _objArchiveCase = objArchiveCase;
     _objArchiveModel = new ArchiveCredentialModel
     {
         BaseSiteUrl = Convert.ToString(ConfigurationManager.AppSettings["BaseSiteUrl"]),
         Username = Convert.ToString(ConfigurationManager.AppSettings["UserName"]),
         Password = Convert.ToString(ConfigurationManager.AppSettings["Password"])
     };
 }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="caseId"></param>
        /// <param name="objArchiveModel"></param>
        /// <returns></returns>
        public string GetCaseFolderDetails(int caseId, ArchiveCredentialModel objArchiveModel)
        {
            string siteUrl = objArchiveModel.BaseSiteUrl;
            try
            {
                Uri uri = new Uri(objArchiveModel.BaseSiteUrl);
                string relativeUrl = uri.AbsolutePath;

                if (objArchiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                    objArchiveModel.BaseSiteUrl += KeywordApi;
                else
                    objArchiveModel.BaseSiteUrl += "/" + KeywordApi;

                string formDigestValue, libraryName = string.Empty, caseFolderName = string.Empty;
                var restClient = RestClientObj(objArchiveModel.BaseSiteUrl, objArchiveModel.Username, objArchiveModel.Password, out formDigestValue);

                int localeId = GetLocaleId(restClient);

                if (Equals(localeId, NorwegianNoLocaleId))
                {
                    libraryName = DocumentLibraryNo;
                    caseFolderName = CaseFolderNameNo;
                }
                else if (Equals(localeId, EnglishUsLocaleId))
                {
                    libraryName = DocumentLibraryEn;
                    caseFolderName = CaseFolderNameEn;
                }

                string folderServerRelativeUrl = string.Concat(relativeUrl, libraryName, "/", caseFolderName, "/", caseId);

                RestRequest request = new RestRequest("web/GetFolderByServerRelativeUrl('" + folderServerRelativeUrl + "')/ListItemAllFields", Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };

                request.AddHeader(Accept, AcceptHeaderVal);
                IRestResponse response = restClient.Execute(request);
                string content = response.Content;

                JObject jobj = JObject.Parse(content);
                string caseFolderDetails = Convert.ToString(jobj["d"]["Id"]);

                objArchiveModel.BaseSiteUrl = siteUrl;

                return string.IsNullOrEmpty(caseFolderDetails) ? CreateCaseFolder(caseId, objArchiveModel) : content;
            }
            catch (Exception)
            {
                objArchiveModel.BaseSiteUrl = siteUrl;
                return CreateCaseFolder(caseId, objArchiveModel);
            }
        }
コード例 #4
0
        public List<ArchiveCaseDocumentDetailModel> GetDocumentsByCaseIdDocumentId(string caseIdDocumentId, ArchiveCredentialModel archiveModel)
        {
            if (archiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                archiveModel.BaseSiteUrl += KeywordApi;
            else
                archiveModel.BaseSiteUrl += "/" + KeywordApi;

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

            int localeId = GetLocaleId(restClient);

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

            RestRequest request = null;
            List<ArchiveCaseDocumentDetailModel> documents = null;
            const string startString = "ADOK-";
            if (caseIdDocumentId.ToLower().StartsWith(startString.ToLower(), StringComparison.Ordinal))
            {
                request = new RestRequest("web/lists/getbytitle('" + libraryName + "')/Items?$select=RegisteredDate,Authority,DocumentStatus,CaseNumber,Origin,PCategory,CategoryOther,PDescription,ContradictionID,DecisionID,PartyID,OwnerID,OData__dlc_DocIdUrl&$filter=_dlc_DocId eq '" + caseIdDocumentId + "'", Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };
                request.AddHeader(Accept, AcceptHeaderVal);
                IRestResponse response = restClient.Execute(request);
                string content = response.Content;

                JObject jobj = JObject.Parse(content);
                var resultsArray = jobj["d"]["results"];

                if (resultsArray.Any())
                {
                    documents = new List<ArchiveCaseDocumentDetailModel>
                                {
                                    (from value in resultsArray.Children()
                                        select new ArchiveCaseDocumentDetailModel
                                        {
                                            RegisteredDate = (DateTime)value["RegisteredDate"],//value["RegisteredDate"].HasValues ? (DateTime)value["RegisteredDate"] : default(DateTime),
                                            Authority = value["Authority"].HasValues ? (string)value["Authority"] : string.Empty,
                                            DocumentStatus = (string)value["DocumentStatus"],
                                            CaseNumber = value["CaseNumber"].HasValues ? (int)value["CaseNumber"] : 0,
                                            Origin = (string)value["Origin"],
                                            Category = (string)value["PCategory"],
                                            CategoryOther = value["CategoryOther"].HasValues ? (string)value["CategoryOther"] : string.Empty,
                                            Description = value["PDescription"].HasValues ? (string)value["PDescription"] : string.Empty,
                                            ContradictionId = (string)value["ContradictionID"],
                                            DecisionId = (string)value["DecisionID"],
                                            PartyId = (string)value["PartyID"],
                                            OwnerId = (string)value["OwnerID"],
                                            CaseDocumentTitle = (string)value["OData__dlc_DocIdUrl"]["Description"],
                                            CaseDocumentUrl = (string)value["OData__dlc_DocIdUrl"]["Url"],
                                            ETag = (string)value["__metadata"]["etag"]
                                        }
                                    ).First()
                                };
                }
            }
            else
            {
                request = new RestRequest("web/lists/getbytitle('" + libraryName + "')/Items?$select=RegisteredDate,Authority,DocumentStatus,CaseNumber,Origin,PCategory,CategoryOther,PDescription,ContradictionID,DecisionID,PartyID,OwnerID,OData__dlc_DocIdUrl&$filter=CaseNumber eq " + caseIdDocumentId, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };
                request.AddHeader(Accept, AcceptHeaderVal);
                request.AddHeader(ContentType, AcceptHeaderVal);
                IRestResponse response = restClient.Execute(request);
                string content = response.Content;

                JObject jobj = JObject.Parse(content);
                var resultsArray = jobj["d"]["results"];

                if (resultsArray.Any())
                {
                    documents = (from value in resultsArray.Children()
                                 select new ArchiveCaseDocumentDetailModel
                                 {
                                     RegisteredDate = (DateTime)value["RegisteredDate"],//value["RegisteredDate"].HasValues ? (DateTime)value["RegisteredDate"] : default(DateTime),
                                     Authority = value["Authority"].HasValues ? (string)value["Authority"] : string.Empty,
                                     DocumentStatus = (string)value["DocumentStatus"],
                                     CaseNumber = value["CaseNumber"].HasValues ? (int)value["CaseNumber"] : 0,
                                     Origin = (string)value["Origin"],
                                     Category = (string)value["PCategory"],
                                     CategoryOther = value["CategoryOther"].HasValues ? (string)value["CategoryOther"] : string.Empty,
                                     Description = value["PDescription"].HasValues ? (string)value["PDescription"] : string.Empty,
                                     ContradictionId = (string)value["ContradictionID"],
                                     DecisionId = (string)value["DecisionID"],
                                     PartyId = (string)value["PartyID"],
                                     OwnerId = (string)value["OwnerID"],
                                     CaseDocumentTitle = (string)value["OData__dlc_DocIdUrl"]["Description"],
                                     CaseDocumentUrl = (string)value["OData__dlc_DocIdUrl"]["Url"],
                                     ETag = (string)value["__metadata"]["etag"]
                                 }
                                ).ToList();
                }
            }

            return documents;
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="caseId"></param>
        /// <param name="archiveModel"></param>
        /// <returns></returns>
        public string CreateCaseFolder(int caseId, ArchiveCredentialModel archiveModel)
        {
            //string siteUrl = archiveModel.BaseSiteUrl;

            Uri uri = new Uri(archiveModel.BaseSiteUrl);
            string relativeUrl = uri.AbsolutePath;

            if (archiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                archiveModel.BaseSiteUrl += KeywordApi;
            else
                archiveModel.BaseSiteUrl += "/" + KeywordApi;

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

            int localeId = GetLocaleId(restClient);

            if (Equals(localeId, NorwegianNoLocaleId))
            {
                libraryName = DocumentLibraryNo;
                caseFolderName = CaseFolderNameNo;
            }
            else if (Equals(localeId, EnglishUsLocaleId))
            {
                libraryName = DocumentLibraryEn;
                caseFolderName = CaseFolderNameEn;
            }

            string folderServerRelativeUrl = string.Concat(relativeUrl, libraryName, "/", caseFolderName, "/", caseId);

            var body = string.Concat("{'__metadata':{'type':'SP.Folder'},",
                                     "'ServerRelativeUrl':'" + folderServerRelativeUrl + "'}");

            RestRequest request = new RestRequest("Web/Folders", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };
            request.AddHeader(Accept, AcceptHeaderVal);
            request.AddHeader(RequestDigest, formDigestValue);
            request.AddHeader(ContentType, AcceptHeaderVal);
            request.AddParameter(AcceptHeaderVal, body, ParameterType.RequestBody);
            //IRestResponse response = restClient.Execute(request);
            restClient.Execute(request);
            //string result = response.Content;
            string resultData = string.Empty;

            //get case folder id
            ItemDetailModel caseFolderDetailsObj = GetItemDetailsByServerRelativeUrl(folderServerRelativeUrl, restClient);
            int caseFolderId = caseFolderDetailsObj.Id;
            string breakInheritanceResponse = BreakChildFolderInheritance(archiveModel, libraryName, caseFolderId);

            var ownersGroup = Convert.ToString((GetTargetGroupId(archiveModel, OwnersGroup)));
            var readersGroup = Convert.ToString((GetTargetGroupId(archiveModel, ReadersGroup)));

            if (breakInheritanceResponse.ToLower().Equals("OK".ToLower()))
            {
                AssignOwnerPermissions(libraryName, caseFolderId, ownersGroup, Fullcontrol, archiveModel);
                AssignFolderPermissions(libraryName, caseFolderId, readersGroup, Read, archiveModel);

                CreateCaseChildFolder(folderServerRelativeUrl, libraryName, archiveModel);
                resultData = "{\"response\":\"All folders under case folder created successfully\"}";
            }

            return resultData;
        }
コード例 #6
0
        public string CaseToArchive(int caseIdToArchive, ArchiveCredentialModel archiveModel)
        {
            Uri uri = new Uri(archiveModel.BaseSiteUrl);
            string relativeUrl = uri.AbsolutePath;

            if (archiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                archiveModel.BaseSiteUrl += KeywordApi;
            else
                archiveModel.BaseSiteUrl += "/" + KeywordApi;

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

            int localeId = GetLocaleId(restClient);
            if (Equals(localeId, NorwegianNoLocaleId))
            {
                libraryName = DocumentLibraryNo;
                caseFolderName = CaseFolderNameNo;
            }
            else if (Equals(localeId, EnglishUsLocaleId))
            {
                libraryName = DocumentLibraryEn;
                caseFolderName = CaseFolderNameEn;
            }

            if (!relativeUrl.EndsWith("/", StringComparison.Ordinal))
            {
                relativeUrl += "/";
            }

            string baseServerRelativeUrl = string.Concat(relativeUrl, "@@/"),
                sourceServerRelativeUrl = string.Empty,
                destinationServerRelativeUrl = string.Empty,
                recordCenterCurrentYearLib = DateTime.Now.Year.ToString();

            string results = IsLibraryExists(recordCenterCurrentYearLib, restClient);
            if (!string.IsNullOrEmpty(results))
            {
                if (results.ToLower().Equals(recordCenterCurrentYearLib.ToLower()))
                {
                    sourceServerRelativeUrl = string.Concat(baseServerRelativeUrl.Replace("@@", libraryName), caseFolderName, "/##");
                    destinationServerRelativeUrl = string.Concat(baseServerRelativeUrl.Replace("@@", recordCenterCurrentYearLib), "##");
                }
                else if (results.ToLower().Equals("-1, System.ArgumentException".ToLower()))
                {
                    return "{\"response\":\"Library: '" + recordCenterCurrentYearLib + "' does not exists\"}";
                }
            }

            string sourceCaseFolderServerRelativeUrl = sourceServerRelativeUrl.Replace("##", caseIdToArchive.ToString()),
                   destCaseFolderServerRelativeUrl = destinationServerRelativeUrl.Replace("##", caseIdToArchive.ToString());

            string caseResult = string.Empty,
                   resultData = string.Empty;
            //RestRequest request = null;
            ItemDetailModel srcCaseFolderDetailVal = GetItemDetailsByServerRelativeUrl(sourceCaseFolderServerRelativeUrl, restClient);
            if (!ReferenceEquals(srcCaseFolderDetailVal, null))
            {
                ItemDetailModel destCaseFolderDetailVal = GetItemDetailsByServerRelativeUrl(destCaseFolderServerRelativeUrl, restClient);
                if (ReferenceEquals(destCaseFolderDetailVal, null))
                {
                    var body = string.Concat(
                            "{'__metadata':{'type':'SP.Folder'},",
                            "'ServerRelativeUrl':'" + destCaseFolderServerRelativeUrl + "'}");

                    RestRequest request = new RestRequest("Web/Folders", Method.POST)
                    {
                        RequestFormat = DataFormat.Json
                    };
                    request.AddHeader(Accept, AcceptHeaderVal);
                    request.AddHeader(RequestDigest, formDigestValue);
                    request.AddHeader(ContentType, AcceptHeaderVal);
                    request.AddParameter(AcceptHeaderVal, body, ParameterType.RequestBody);
                    IRestResponse response = restClient.Execute(request);
                    JObject jobject = JObject.Parse(response.Content);

                    // TODO: Check is not working on Test Environment on our test site
                    //if (Convert.ToString(jobject["d"]["ServerRelativeUrl"]).Equals(destCaseFolderServerRelativeUrl))
                    {
                        foreach (string folderTitle in _templateFolders)
                        {
                            string subfolderRelativeUrl = string.Concat(destCaseFolderServerRelativeUrl, "/", folderTitle);
                            body = string.Concat(
                                "{'__metadata':{'type':'SP.Folder'},",
                                "'ServerRelativeUrl':'" + subfolderRelativeUrl + "'}");

                            request = new RestRequest("Web/Folders", Method.POST)
                            {
                                RequestFormat = DataFormat.Json
                            };
                            request.AddHeader(Accept, AcceptHeaderVal);
                            request.AddHeader(RequestDigest, formDigestValue);
                            request.AddHeader(ContentType, AcceptHeaderVal);
                            request.AddParameter(AcceptHeaderVal, body, ParameterType.RequestBody);
                            response = restClient.Execute(request);

                            jobject = JObject.Parse(response.Content);
                            if (Convert.ToString(jobject["d"]["ServerRelativeUrl"]).Equals(subfolderRelativeUrl))
                            {
                                caseResult += string.Empty;
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(caseResult))
                    {
                        foreach (string folderName in _templateFolders)
                        {
                            string sourceUrl = sourceCaseFolderServerRelativeUrl + "/" + folderName;
                            ItemDetailModel srcCaseFolderDetailVal2 = GetItemDetailsByServerRelativeUrl(sourceUrl, restClient);
                            if (!ReferenceEquals(srcCaseFolderDetailVal2, null))
                            {
                                string destinationUrl = destCaseFolderServerRelativeUrl + "/" + folderName;
                                request = new RestRequest("web/GetFolderByServerRelativeUrl('" + sourceUrl + "')/Files?$select=Name", Method.GET)
                                {
                                    RequestFormat = DataFormat.Json
                                };
                                request.AddHeader(Accept, AcceptHeaderVal);

                                response = restClient.Execute(request);

                                JObject jobj = JObject.Parse(response.Content);
                                var result = jobj["d"]["results"];
                                if (!ReferenceEquals(result, null) && result.Any())
                                {
                                    List<string> caseFileNameCollection = (from value in result.Children()
                                                                           select Convert.ToString(value["Name"])
                                                                          ).ToList();

                                    int caseFileNameCount = caseFileNameCollection.Count, index = 0;

                                    for (; index < caseFileNameCount; index++)
                                    {
                                        string srcUrl = sourceUrl, destUrl = destinationUrl;
                                        srcUrl += "/" + caseFileNameCollection[index];
                                        destUrl += "/" + caseFileNameCollection[index];

                                        request = new RestRequest("web/GetFileByServerRelativeUrl('" + srcUrl + "')/moveto(newurl='" + destUrl + "', flags=1)", Method.POST)
                                        {
                                            RequestFormat = DataFormat.Json
                                        };
                                        request.AddHeader(Accept, AcceptHeaderVal);
                                        request.AddHeader(RequestDigest, formDigestValue);
                                        IRestResponse caseDocumentResponse = restClient.Execute(request);

                                        jobject = JObject.Parse(caseDocumentResponse.Content);
                                        if (ReferenceEquals(jobject["d"]["MoveTo"], null))
                                        {
                                            caseResult += string.Empty;
                                        }
                                    }

                                    // TODO: rethink on this.
                                    //if (resultData.Equals("Case Documents moved and archived successfully"))
                                    //{
                                    //    resultData = string.IsNullOrEmpty(caseResult)
                                    //                                ? "Case Documents moved and archived successfully"
                                    //                                : "sError- Try again";
                                    //}
                                    //else
                                    //{
                                    //    resultData = string.IsNullOrEmpty(caseResult)
                                    //                                ? resultData + "Case Documents moved and archived successfully"
                                    //                                : resultData + "Error- Try again";
                                    //}
                                    // TODO
                                }
                                //else
                                //{
                                //    if (resultData.Equals("No Documents"))
                                //    {
                                //        resultData = "No Documents";
                                //    }
                                //    else
                                //    {
                                //        resultData += "No Documents";
                                //    }
                                //}
                            }
                            else
                            {
                                resultData = "Folder Does not exists under Destination Case";
                            }
                        }

                        // TODO: delete source case folder now;
                        request = new RestRequest("web/GetFolderByServerRelativeUrl('" + sourceCaseFolderServerRelativeUrl + "')", Method.POST)
                        {
                            RequestFormat = DataFormat.Json
                        };
                        request.AddHeader(Accept, AcceptHeaderVal);
                        request.AddHeader(HttpMethod, Method.DELETE.ToString());
                        request.AddHeader(IfMatch, srcCaseFolderDetailVal.ETag);
                        request.AddHeader(RequestDigest, formDigestValue);

                        response = restClient.Execute(request);
                        resultData = string.IsNullOrEmpty(response.Content) ? "Case Documents moved and archived successfully" : "Error- Try again";
                    }
                }
                else
                {
                    resultData = "Case already archived at:" + destCaseFolderServerRelativeUrl;
                }
            }
            else
            {
                resultData += "Source Case Folder Does not exists";
            }
            return "{\"response\":\"" + resultData + "\"}";
        }
コード例 #7
0
        public string CopyCaseDocuments(int sourceCaseId, int destinationCaseId, ArchiveCredentialModel archiveModel, string copyFlag)
        {
            string cusMsg = string.Empty;
            List<string> folderToCopyData = new List<string>
            {
                TempSaksdokumenter,TempBeslutning
            };
            try
            {
                Uri uri = new Uri(archiveModel.BaseSiteUrl);
                string relativeUrl = uri.AbsolutePath;

                if (archiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                    archiveModel.BaseSiteUrl += KeywordApi;
                else
                    archiveModel.BaseSiteUrl += "/" + KeywordApi;

                string formDigestValue, libraryName = string.Empty, caseFolderName = string.Empty;

                var restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);
                cusMsg += "\n  rest client and form digest fetched  ";
                int localeId = GetLocaleId(restClient);
                if (Equals(localeId, NorwegianNoLocaleId))
                {
                    libraryName = DocumentLibraryNo;
                    caseFolderName = CaseFolderNameNo;
                }
                else if (Equals(localeId, EnglishUsLocaleId))
                {
                    libraryName = DocumentLibraryEn;
                    caseFolderName = CaseFolderNameEn;
                }

                if (!relativeUrl.EndsWith("/", StringComparison.Ordinal))
                {
                    relativeUrl += "/";
                }

                string baseServerRelativeUrl = string.Concat(relativeUrl, "#1#/"),//@@
                    sourceServerRelativeUrl = string.Empty,
                    destinationServerRelativeUrl = string.Empty,
                    recordCenterCurrentYearLib = string.Empty;

                //RestRequest request = null;

                if (copyFlag.ToLower().Equals("RecordCenter".ToLower()))
                {
                    recordCenterCurrentYearLib = DateTime.Now.Year.ToString();

                    string results = IsLibraryExists(recordCenterCurrentYearLib, restClient);
                    cusMsg += "\n  checking library exists   ";
                    if (!string.IsNullOrEmpty(results))
                    {
                        if (results.ToLower().Equals(recordCenterCurrentYearLib.ToLower()))
                        {
                            sourceServerRelativeUrl = string.Concat(baseServerRelativeUrl.Replace("#1#", recordCenterCurrentYearLib), "##");//@@
                            destinationServerRelativeUrl = string.Concat(baseServerRelativeUrl.Replace("#1#", libraryName), caseFolderName, "/##");//@@
                        }
                        else if (results.ToLower().Equals("-1, System.ArgumentException".ToLower()))
                        {
                            return "{\"response\":\"Library: '" + recordCenterCurrentYearLib + "' does not exists\"}";
                        }
                    }
                }
                else if (copyFlag.ToLower().Equals("NotRecordCenter".ToLower()))
                {
                    sourceServerRelativeUrl = string.Concat(baseServerRelativeUrl.Replace("#1#", libraryName), caseFolderName, "/##");//@@
                    destinationServerRelativeUrl = sourceServerRelativeUrl;
                    cusMsg += "\n  " + destinationServerRelativeUrl + "  ";
                }

                string sourceCaseFolderServerRelativeUrl = sourceServerRelativeUrl.Replace("##", sourceCaseId.ToString()),
                       destCaseFolderServerRelativeUrl = destinationServerRelativeUrl.Replace("##", destinationCaseId.ToString());

                string caseResult = string.Empty, resultData = string.Empty;

                ItemDetailModel srcCaseFolderDetailVal = GetItemDetailsByServerRelativeUrl(sourceCaseFolderServerRelativeUrl, restClient);
                if (!ReferenceEquals(srcCaseFolderDetailVal, null))
                {
                    /* commented by vikas */
                    //string srcURL = sourceCaseFolderServerRelativeUrl;
                    //string destURL = destCaseFolderServerRelativeUrl;

                    ItemDetailModel destCaseFolderDetailVal = GetItemDetailsByServerRelativeUrl(destCaseFolderServerRelativeUrl, restClient);
                    if (!ReferenceEquals(destCaseFolderDetailVal, null))
                    {
                        foreach (string folderName in folderToCopyData)
                        {
                            string sourceUrl = sourceCaseFolderServerRelativeUrl + "/" + folderName;

                            ItemDetailModel srcCaseFolderDetailVal2 = GetItemDetailsByServerRelativeUrl(sourceUrl, restClient);
                            if (!ReferenceEquals(srcCaseFolderDetailVal2, null))
                            {
                                string destinationUrl = destCaseFolderServerRelativeUrl + "/" + folderName;

                                ItemDetailModel destCaseFolderDetailVal2 = GetItemDetailsByServerRelativeUrl(destinationUrl, restClient);
                                if (!ReferenceEquals(destCaseFolderDetailVal2, null))
                                {
                                    RestRequest request = null;
                                    request = new RestRequest("web/GetFolderByServerRelativeUrl('" + sourceUrl + "')/Files?$select=Name&$orderby=Name", Method.GET)
                                    {
                                        RequestFormat = DataFormat.Json
                                    };
                                    request.AddHeader(Accept, AcceptHeaderVal);

                                    IRestResponse response = restClient.Execute(request);
                                    string result = response.Content;

                                    JObject jobj = JObject.Parse(result);

                                    var results = jobj["d"]["results"];

                                    if (!ReferenceEquals(results, null) && results.Any())
                                    {
                                        List<string> caseFileNameCollection = (from value in results.Children()
                                                                               select Convert.ToString(value["Name"])
                                                                              ).ToList();

                                        //List<string> caseFileNameCollection = new List<string>();

                                        //foreach (var value in results.Children())
                                        //{
                                        //    caseFileNameCollection.Add(Convert.ToString(value["Name"]));
                                        //}

                                        int caseFileNameCount = caseFileNameCollection.Count, index;
                                        for (index = 0; index < caseFileNameCount; index++)
                                        {
                                            cusMsg += "\n  Form Digest : " + formDigestValue + ",,,," + caseFileNameCount + "  ";
                                            string srcUrl = sourceUrl, destUrl = destinationUrl;
                                            srcUrl += "/" + caseFileNameCollection[index];
                                            destUrl += "/" + caseFileNameCollection[index];

                                            //  resultData = resultData + "web/GetFileByServerRelativeUrl('" + srcUrl + "')/copyto(strnewurl='" + destUrl + "', boverwrite = true)";
                                            cusMsg += "\n  " + srcUrl + "  \n  " + destUrl + "  ";
                                            //string myUrl = "web/GetFileByServerRelativeUrl('" + srcUrl + "')/copyto(strnewurl='" + destUrl + "',boverwrite=true)";

                                            request = new RestRequest("web/getfilebyserverrelativeUrl('" + srcUrl + "')/copyto(strnewurl='" + destUrl + "',boverwrite=true)", Method.POST)
                                            {
                                                RequestFormat = DataFormat.Json
                                            };

                                            //cusMsg += "  $$  " + archiveModel.BaseSiteUrl + myUrl + "  $$  ";
                                            request.AddHeader(Accept, AcceptHeaderVal);
                                            request.AddHeader(RequestDigest, formDigestValue);

                                            IRestResponse caseDocumentResponse = restClient.Execute(request);

                                            //JObject jobject = JObject.Parse(caseDocumentResponse.Content);
                                            //bool isResponseExists = jobject["d"]["CopyTo"].HasValues;
                                            //if (!isResponseExists)
                                            //{
                                            //    caseResult += string.Empty;
                                            //}

                                            if (Equals(caseDocumentResponse.StatusCode, HttpStatusCode.OK))
                                            {
                                                caseResult += string.Empty;
                                            }

                                            cusMsg += "\n  " + caseDocumentResponse.StatusCode + "  ";
                                        }
                                        // resultData = resultData + " Data Copied";
                                        if (resultData.Equals("Case Documents copied successfully"))
                                        {
                                            resultData = string.IsNullOrEmpty(caseResult)
                                                         ? "Case Documents copied successfully" //+ cusMsg
                                                         : "sError- Try again";
                                        }
                                        else
                                        {
                                            resultData = string.IsNullOrEmpty(caseResult)
                                                         ? resultData + "Case Documents copied successfully" //+ cusMsg
                                                         : resultData + "Error- Try again";
                                        }
                                    }
                                    else
                                    {
                                        if (resultData.Equals("No Documents"))
                                        {
                                            resultData = "No Documents";
                                        }
                                        else
                                        {
                                            resultData += "No Documents";
                                        }
                                        // return "{\"response\":\"No Documents\"}";
                                    }
                                }
                                else
                                {
                                    // return "{\"response\":\"Folder Does not exists under Destination Case\"}";
                                    resultData = "Folder Does not exists under Destination Case";
                                }
                            }
                            else
                            {
                                //  return "{\"response\":\"Folder Does not exists under Source Case\"}";
                                resultData = "Folder Does not exists under Source Case";
                            }
                        }
                    }
                    else
                    {
                        //return "{\"response\":\"Destination Case Folder Does not exists\"}";
                        resultData = "Destination Case Folder Does not exists";
                    }
                }
                else
                {
                    resultData += "Source Case Folder Does not exists";
                }

                //return string.IsNullOrEmpty(caseResult)
                //                            ? "{\"response\":\"Case Documents copied successfully\"}"
                //                            : "{\"response\":\"Error- Try again\"}";
                //      return "{\"response\":\"Source Case Folder Does not exists\"}";
                resultData = "{\"response\":\"" + resultData + "\"}";
                return resultData;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
コード例 #8
0
        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.\"}";
            }
        }
コード例 #9
0
        public string DeleteCaseDocument(string documentId, ArchiveCredentialModel objArchiveModel)
        {
            //string startString = "ADOK";
            //if (documentId.Trim().ToLower().StartsWith(startString.ToLower(), StringComparison.Ordinal))
            //{
            if (objArchiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                objArchiveModel.BaseSiteUrl += KeywordApi;
            else
                objArchiveModel.BaseSiteUrl += "/" + KeywordApi;

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

            int localeId = GetLocaleId(restClient);

            if (Equals(localeId, NorwegianNoLocaleId))
            {
                libraryName = DocumentLibraryNo;
                documentStatus = DeletedNo;
            }
            else if (Equals(localeId, EnglishUsLocaleId))
            {
                libraryName = DocumentLibraryEn;
                documentStatus = DeletedEn;
            }

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

            //string body = string.Empty;

            if (!ReferenceEquals(listItemDetailObj, null))
            {
                //if (!string.IsNullOrEmpty(deleteFlag))//(!ReferenceEquals(deleteFlag, null))
                //{
                string body = string.Concat(
                        "{",
                        "'__metadata':{'type':'" + listItemDetailObj.ListItemEntityTypeFullName + "'},",
                        "'DocumentStatus':'" + 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 status updated successfully\"}" : "{\"response\":\"Error- Try again\"}";
                //}
            }
            //if (string.IsNullOrEmpty(body))
            //{
            return "{\"response\":\"Document does not exists\"}";
            //}
            //}
            //return "{\"response\":\"Wrong Pattern entered for Document ID\"}";
        }
コード例 #10
0
        public string UploadDocumentInCaseFolder(int caseId, ArchiveCaseFileModel fileDataObj, ArchiveCredentialModel archiveModel)
        {
            string extension = Path.GetExtension(fileDataObj.FileName);
            if (!string.IsNullOrEmpty(extension))
            {
                Match match = Regex.Match(extension, @".*\.(xls|xlsx|jpg|jpeg|gif|png|doc|docx|pdf|pptx|ppt|txt)?$", RegexOptions.IgnoreCase);

                if (match.Success)
                {
                    Uri uri = new Uri(archiveModel.BaseSiteUrl);
                    string relativeUrl;
                    if (!archiveModel.BaseSiteUrl.Contains(KeywordApi))
                    {
                        relativeUrl = uri.AbsolutePath;
                        if (archiveModel.BaseSiteUrl.EndsWith("/", StringComparison.Ordinal))
                            archiveModel.BaseSiteUrl += KeywordApi;
                        else
                            archiveModel.BaseSiteUrl += "/" + KeywordApi;
                    }
                    else
                    {
                        Uri uri1 = new Uri(uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - uri.Segments.Last().Length));
                        relativeUrl = uri1.AbsolutePath;
                    }
                    string formDigestValue, libraryName = string.Empty, caseFolderName = string.Empty, documentStatusValue = string.Empty;
                    var restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

                    int localeId = GetLocaleId(restClient);

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

                    string folderServerRelativeUrl = string.Concat(relativeUrl, libraryName, "/", caseFolderName, "/", caseId, "/Saksdokumenter");

                    //RestRequest request = null;
                    RestRequest request = new RestRequest("web/GetFolderByServerRelativeUrl('" + folderServerRelativeUrl + "')/files/add(url='" + fileDataObj.FileName + "',overwrite='true')", Method.POST)
                    {
                        RequestFormat = DataFormat.Json
                    };
                    request.AddHeader(Accept, AcceptHeaderVal);
                    request.AddHeader(ContentType, AcceptHeaderVal);
                    request.AddHeader(RequestDigest, formDigestValue);
                    request.AddHeader(BinaryStringRequestBody, "true");
                    request.AddParameter(AcceptHeaderVal, fileDataObj.FileData, ParameterType.RequestBody);
                    //IRestResponse response = restClient.Execute(request);
                    restClient.Execute(request);

                    //JObject jobj = JObject.Parse(response.Content);

                    string serverRelativeUrlOfFile = string.Concat(folderServerRelativeUrl, "/", fileDataObj.FileName);
                    ItemDetailModel listItemDetailObj = GetItemDetailsByServerRelativeUrl(serverRelativeUrlOfFile, restClient);

                    var body = string.Concat(
                                "{",
                                "'__metadata':{'type':'" + listItemDetailObj.ListItemEntityTypeFullName + "'},",
                                "'DocumentStatus':'" + documentStatusValue + "'",
                                "}");

                    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 updateResponse = restClient.Execute(request);
                    restClient.Execute(request);

                    string file = Path.GetFileNameWithoutExtension(serverRelativeUrlOfFile),
                           documentName = listItemDetailObj.DocumentName,
                           newPath = serverRelativeUrlOfFile.Replace(file, documentName);

                    return "{\"response\":\"Case Document uploaded successfully at: " + newPath + " and to update metadata call /Documents/{documentId} of type PUT\",\"CaseDocumentName\":\"" + documentName + "\"}";
                }
            }
            return "{\"response\":\"Invalid file Extension " + extension + "\"}";
        }
コード例 #11
0
        private static void AssignOwnerPermissions(string listTitle, int listItemId, string groupId, string roleDefiId, ArchiveCredentialModel archiveModel)
        {
            string formDigestValue;
            var restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

            RestRequest request = new RestRequest("web/lists/getbytitle('" + listTitle + "')/Items(" + listItemId + ")/roleassignments/addroleassignment(principalid='" + groupId + "',roledefid='" + roleDefiId + "')", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };
            request.AddHeader(Accept, AcceptHeaderVal);
            request.AddHeader(ContentType, AcceptHeaderVal);
            request.AddHeader(RequestDigest, formDigestValue);
            //IRestResponse response = restClient.Execute(request);
            restClient.Execute(request);
            //return response.Content;
        }
コード例 #12
0
        //******************************************************************************************************************************************************************//

        /// <summary>
        /// Set permissions on the "Saksdokumenter" library as per parameters
        /// </summary>
        /// <param name="caseId"></param>
        /// <param name="folderName"></param>
        /// <param name="archiveModel"></param>
        /// <returns></returns>
        public string SetPermission(int caseId, string folderName, ArchiveCredentialModel archiveModel)
        {
            if (folderName.ToLower().Equals(NemndResource.ToLower()) || folderName.ToLower().Equals(UtvalgResource.ToLower()))
            {
                Uri uri = new Uri(archiveModel.BaseSiteUrl);
                string relativeUrl = uri.AbsolutePath;

                string targetSiteUrl = archiveModel.BaseSiteUrl;
                if (targetSiteUrl.EndsWith("/", StringComparison.Ordinal))
                    targetSiteUrl += KeywordApi;
                else
                    targetSiteUrl += "/" + KeywordApi;
                archiveModel.BaseSiteUrl = targetSiteUrl;

                string formDigestValue, libraryName = string.Empty, caseFolderName = string.Empty;
                var restClient = RestClientObj(targetSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

                int localeId = GetLocaleId(restClient);

                if (Equals(localeId, NorwegianNoLocaleId))
                {
                    libraryName = DocumentLibraryNo;
                    caseFolderName = CaseFolderNameNo;
                }
                else if (Equals(localeId, EnglishUsLocaleId))
                {
                    libraryName = DocumentLibraryEn;
                    caseFolderName = CaseFolderNameEn;
                }

                var nemndRead = Convert.ToString(GetTargetGroupId(archiveModel, NemndReaderGroup));
                var nemndContribute = Convert.ToString(GetTargetGroupId(archiveModel, NemndContributeGroup));
                var utvalgContribute = Convert.ToString(GetTargetGroupId(archiveModel, UtvalgContributeGroup));
                var utvalgRead = Convert.ToString(GetTargetGroupId(archiveModel, UtvalgReaderGroup));

                string result = string.Empty;
                //string removeExistingPermissions = string.Empty;

                List<string> templateFolders = new List<string>
                {
                    TempBeslutning,
                    TempSladdetBeslutning,
                    TempSaksdokumenter
                };

                foreach (string folderTitle in templateFolders)
                {
                    string caseFolderServerRelativeUrl = string.Concat(relativeUrl, libraryName, "/", caseFolderName, "/", caseId, "/", folderTitle);
                    ItemDetailModel caseFolderDetailsObj = GetItemDetailsByServerRelativeUrl(caseFolderServerRelativeUrl, restClient);

                    if (ReferenceEquals(caseFolderDetailsObj, null))
                    {
                        return "{\"response\":\"error\"}";
                    }

                    int caseFolderId = caseFolderDetailsObj.Id;

                    if (folderName.ToLower().Equals(NemndResource))
                    {
                        if (folderTitle.ToLower().Equals(TempSaksdokumenter.ToLower()))
                        {
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, utvalgRead, archiveModel);
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, utvalgContribute, archiveModel);

                            RemoveFolderPermissions(libraryName, caseFolderId, utvalgRead, archiveModel);
                            RemoveFolderPermissions(libraryName, caseFolderId, utvalgContribute, archiveModel);

                            result += AssignFolderPermissions(libraryName, caseFolderId, nemndContribute, Contribute, archiveModel);
                            result += AssignFolderPermissions(libraryName, caseFolderId, nemndRead, Read, archiveModel);
                        }
                        else
                        {
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, nemndRead, archiveModel);
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, utvalgContribute, archiveModel);

                            RemoveFolderPermissions(libraryName, caseFolderId, nemndRead, archiveModel);
                            RemoveFolderPermissions(libraryName, caseFolderId, utvalgContribute, archiveModel);

                            result += AssignFolderPermissions(libraryName, caseFolderId, nemndContribute, Contribute, archiveModel);
                            result += AssignFolderPermissions(libraryName, caseFolderId, utvalgRead, Read, archiveModel);
                        }
                    }

                    if (folderName.ToLower().Equals(UtvalgResource))
                    {
                        if (folderTitle.ToLower().Equals(TempSaksdokumenter.ToLower()))
                        {
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, nemndContribute, archiveModel);
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, nemndRead, archiveModel);

                            RemoveFolderPermissions(libraryName, caseFolderId, nemndContribute, archiveModel);
                            RemoveFolderPermissions(libraryName, caseFolderId, nemndRead, archiveModel);

                            result += AssignFolderPermissions(libraryName, caseFolderId, utvalgContribute, Contribute, archiveModel);
                            result += AssignFolderPermissions(libraryName, caseFolderId, utvalgRead, Read, archiveModel);
                        }
                        else
                        {
                            //removeExistingPermissions = RemoveFolderPermissions(libraryName, caseFolderId, utvalgRead, archiveModel);
                            //removeExistingPermissions += RemoveFolderPermissions(libraryName, caseFolderId, nemndContribute, archiveModel);

                            RemoveFolderPermissions(libraryName, caseFolderId, utvalgRead, archiveModel);
                            RemoveFolderPermissions(libraryName, caseFolderId, nemndContribute, archiveModel);

                            result += AssignFolderPermissions(libraryName, caseFolderId, utvalgContribute, Contribute, archiveModel);
                            result += AssignFolderPermissions(libraryName, caseFolderId, nemndRead, Read, archiveModel);
                        }
                    }
                }

                if (result.ToLower().Contains("error"))
                    return "{\"response\":\"error try again later\"}";
                return "{\"response\":\"Permissions assigned successfully for " + folderName + " group.\"}";
            }
            else
            {
                return "{\"response\":\"Wrong Authority name entered\"}";
            }
        }
コード例 #13
0
        private void SetFolderPermissions(string folderTitle, string libraryName, int caseFolderId, ArchiveCredentialModel archiveModel)
        {
            //string targetSiteUrl = archiveModel.BaseSiteUrl;

            var ownerGroup = Convert.ToString((GetTargetGroupId(archiveModel, OwnersGroup)));

            if (!folderTitle.ToLower().Equals(TempSladdetBeslutning.ToLower()))
            {
                AssignOwnerPermissions(libraryName, caseFolderId, ownerGroup, Fullcontrol, archiveModel);
            }

            //string result = string.Empty;

            if (folderTitle.ToLower().Equals(TempNemndLib.ToLower()))
            {
                var nemndRead = Convert.ToString(GetTargetGroupId(archiveModel, NemndReaderGroup));
                var nemndContribute = Convert.ToString(GetTargetGroupId(archiveModel, NemndContributeGroup));
                //result += AssignFolderPermissions(libraryName, caseFolderId, nemndContribute, Contribute, archiveModel);
                //result += AssignFolderPermissions(libraryName, caseFolderId, nemndRead, Read, archiveModel);
                AssignFolderPermissions(libraryName, caseFolderId, nemndContribute, Contribute, archiveModel);
                AssignFolderPermissions(libraryName, caseFolderId, nemndRead, Read, archiveModel);
            }

            if (folderTitle.ToLower().Equals(TempUtvalgLib.ToLower()))
            {
                var utvalgContribute = Convert.ToString(GetTargetGroupId(archiveModel, UtvalgContributeGroup));
                var utvalgRead = Convert.ToString(GetTargetGroupId(archiveModel, UtvalgReaderGroup));
                //result += AssignFolderPermissions(libraryName, caseFolderId, utvalgContribute, Contribute, archiveModel);
                //result += AssignFolderPermissions(libraryName, caseFolderId, utvalgRead, Read, archiveModel);
                AssignFolderPermissions(libraryName, caseFolderId, utvalgContribute, Contribute, archiveModel);
                AssignFolderPermissions(libraryName, caseFolderId, utvalgRead, Read, archiveModel);
            }
            //return string.Empty;
        }
コード例 #14
0
        private void CreateCaseChildFolder(string folderServerRelativeUrl, string libraryName, ArchiveCredentialModel archiveModel)
        {
            string formDigestValue;
            var restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

            //List<string> templateFolders = new List<string>
            //{
            //    TempUtvalgLib,
            //    TempNemndLib,
            //    TempSaksdokumenter,
            //    TempBeslutning,
            //    TempSladdetBeslutning
            //};

            foreach (string folderTitle in _templateFolders)
            {
                var body = string.Concat(
                    "{'__metadata':{'type':'SP.Folder'},",
                    "'ServerRelativeUrl':'" + folderServerRelativeUrl + "/" + folderTitle + "'}");

                RestRequest request = new RestRequest("Web/Folders", Method.POST)
                {
                    RequestFormat = DataFormat.Json
                };
                request.AddHeader(Accept, AcceptHeaderVal);
                request.AddHeader(RequestDigest, formDigestValue);
                request.AddHeader(ContentType, AcceptHeaderVal);
                request.AddParameter(AcceptHeaderVal, body, ParameterType.RequestBody);
                //IRestResponse response = restClient.Execute(request);
                restClient.Execute(request);
                //string result = response.Content;

                ItemDetailModel caseFolderDetailsObj = GetItemDetailsByServerRelativeUrl(folderServerRelativeUrl + "/" + folderTitle, restClient);
                int caseFolderId = caseFolderDetailsObj.Id;
                BreakChildFolderInheritance(archiveModel, libraryName, caseFolderId);
                SetFolderPermissions(folderTitle, libraryName, caseFolderId, archiveModel);
            }
            //return "Child folder created ";
        }
コード例 #15
0
        private string BreakChildFolderInheritance(ArchiveCredentialModel archiveModel, string listTitle, int listItemId)
        {
            string formDigestValue;
            var restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

            RestRequest request = new RestRequest("web/lists/GetByTitle('" + listTitle + "')/getItemById(" + listItemId + ")/breakroleinheritance", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };
            request.AddHeader(Accept, AcceptHeaderVal);
            request.AddHeader(RequestDigest, formDigestValue);
            IRestResponse response = restClient.Execute(request);

            if (Equals((HttpStatusCode)response.StatusCode, HttpStatusCode.OK))
            {
                return "OK";
            }
            return string.Empty;
            //return Convert.ToString(response.StatusCode);
        }
コード例 #16
0
        /// <summary>
        /// Get the target group id to assign the permissions
        /// </summary>
        /// <param name="archiveModel"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        private static string GetTargetGroupId(ArchiveCredentialModel archiveModel, string groupName)
        {
            string formDigestValue;
            var restClient = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

            RestRequest request = new RestRequest("web/sitegroups/getbyname('" + groupName.Trim() + "')/id", Method.GET)
            {
                RequestFormat = DataFormat.Json
            };
            request.AddHeader(Accept, AcceptHeaderVal);
            string content = restClient.Execute(request).Content;

            JObject jobj = JObject.Parse(content);
            string groupId = Convert.ToString(jobj["d"]["Id"]);
            return groupId;
        }
コード例 #17
0
        private static void RemoveFolderPermissions(string listTitle, int listItemId, string groupId, ArchiveCredentialModel archiveModel)
        {
            string formDigestValue;
            var rc = RestClientObj(archiveModel.BaseSiteUrl, archiveModel.Username, archiveModel.Password, out formDigestValue);

            RestRequest request = new RestRequest("web/lists/getbytitle('" + listTitle + "')/Items(" + listItemId + ")/roleassignments/getbyprincipalid('" + groupId + "')", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };
            request.AddHeader(Accept, AcceptHeaderVal);
            request.AddHeader(ContentType, AcceptHeaderVal);
            request.AddHeader(RequestDigest, formDigestValue);
            request.AddHeader(HttpMethod, Method.DELETE.ToString());
            //IRestResponse response = rc.Execute(request);
            rc.Execute(request);
            //string content = response.Content;
            //return Convert.ToString(response.StatusCode);
            //return response.StatusCode;
        }