Ejemplo n.º 1
0
 public bool CreateList(ClientContext clientContext, ListInformation listInfo)
 {
     bool result = true;
     if (null != clientContext && null != listInfo && !string.IsNullOrWhiteSpace(listInfo.name))
     {
         Web web = clientContext.Web;
         ListTemplateCollection listTemplates = web.ListTemplates;
         ListCreationInformation creationInfo = new ListCreationInformation();
         creationInfo.Title = listInfo.name;
         creationInfo.Description = listInfo.description;
         // To determine changes in URL we specified below condition as this function is common
         if (!string.IsNullOrWhiteSpace(listInfo.Path))
         {
             creationInfo.Url = listInfo.Path;
         }
         if (!string.IsNullOrWhiteSpace(listInfo.templateType))
         {
             string templateType = listInfo.templateType;
             clientContext.Load(listTemplates, item => item.Include(currentTemplate => currentTemplate.Name, currentTemplate => 
                     currentTemplate.ListTemplateTypeKind).Where(selectedTemplate => selectedTemplate.Name == templateType));
             clientContext.ExecuteQuery();
             if (null != listTemplates && 0 < listTemplates.Count)
             {
                 creationInfo.TemplateType = listTemplates.FirstOrDefault().ListTemplateTypeKind;
             }
             else
             {
                 result = false;
             }
         }
         else
         {
             creationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary;
         }
         if (result)
         {
             List list = web.Lists.Add(creationInfo);
             list.ContentTypesEnabled = listInfo.isContentTypeEnable;
             if (null != listInfo.folderNames && listInfo.folderNames.Count > 0)
             {
                 list = AddFolders(clientContext, list, listInfo.folderNames);
             }
             if (null != listInfo.versioning)
             {
                 list.EnableVersioning = listInfo.versioning.EnableVersioning;
                 list.EnableMinorVersions = listInfo.versioning.EnableMinorVersions;
                 list.ForceCheckout = listInfo.versioning.ForceCheckout;
             }
             list.Update();
             clientContext.Load(list, l => l.DefaultViewUrl);
             clientContext.ExecuteQuery();
             result = true;
         }
     }
     return result;
 }
Ejemplo n.º 2
0
        private GenericResponseVM CreateMatter(ClientContext clientContext, MatterMetdataVM matterMetadataVM)
        {
            var client = matterMetadataVM.Client;
            var matter = matterMetadataVM.Matter;
            GenericResponseVM genericResponseVM = null;
            try
            {
                var matterConfiguration = matterMetadataVM.MatterConfigurations;
                Uri centralListURL = new Uri(string.Concat(generalSettings.CentralRepositoryUrl, ServiceConstants.FORWARD_SLASH,
                    ServiceConstants.LISTS, ServiceConstants.FORWARD_SLASH, listNames.DMSMatterListName)); // Central Repository List URL  
                IList<string> documentLibraryFolders = new List<string>();
                Dictionary<string, bool> documentLibraryVersioning = new Dictionary<string, bool>();
                Uri clientUrl = new Uri(client.Url);
                string matterOneNoteTitle = TrimMatterNameForOneNoteTitle(matter.Name);
                ListInformation listInformation = new ListInformation();
                listInformation.name = matter.Name;
                listInformation.description = matter.Description;
                listInformation.folderNames = matter.FolderNames;
                listInformation.isContentTypeEnable = true;
                listInformation.versioning = new VersioningInfo();
                listInformation.versioning.EnableVersioning = matterSettings.IsMajorVersionEnable;
                listInformation.versioning.EnableMinorVersions = matterSettings.IsMinorVersionEnable;
                listInformation.versioning.ForceCheckout = matterSettings.IsForceCheckOut;
                listInformation.Path = matter.MatterGuid;

                matterRepositoy.CreateList(clientContext, listInformation);

                documentLibraryVersioning.Add("EnableVersioning", false);
                documentLibraryFolders.Add(matterOneNoteTitle);
                listInformation.name = matter.Name + matterSettings.OneNoteLibrarySuffix;
                listInformation.folderNames = documentLibraryFolders;
                listInformation.versioning.EnableVersioning = false;
                listInformation.versioning.EnableMinorVersions = false;
                listInformation.versioning.ForceCheckout = false;
                listInformation.Path = matter.MatterGuid + matterSettings.OneNoteLibrarySuffix;
                matterRepositoy.CreateList(clientContext, listInformation);

                bool isCopyRoleAssignment = CopyRoleAssignment(matter.Conflict.Identified, matter.Conflict.SecureMatter);
                //create calendar list if create calendar flag is enabled and break its permissions
                string calendarName = string.Concat(matter.Name, matterSettings.CalendarNameSuffix);
                string taskListName = string.Concat(matter.Name, matterSettings.TaskNameSuffix);

                if (matterSettings.IsCreateCalendarEnabled && matterConfiguration.IsCalendarSelected)
                {
                    ListInformation calendarInformation = new ListInformation();
                    calendarInformation.name = calendarName;
                    calendarInformation.isContentTypeEnable = false;
                    calendarInformation.templateType = ServiceConstants.CALENDAR_NAME;
                    calendarInformation.Path = matterSettings.TitleListsPath + matter.MatterGuid + matterSettings.CalendarNameSuffix;

                    if (matterRepositoy.CreateList(clientContext, calendarInformation))
                    {
                        matterRepositoy.BreakPermission(clientContext, calendarName, isCopyRoleAssignment);
                    }
                    else
                    {
                        return ServiceUtility.GenericResponse(errorSettings.ErrorCodeAddCalendarList, errorSettings.ErrorMessageAddCalendarList);
                    }
                }

                if (matterConfiguration.IsTaskSelected)
                {
                    ListInformation taskListInformation = new ListInformation();
                    taskListInformation.name = taskListName;
                    taskListInformation.isContentTypeEnable = false;
                    taskListInformation.templateType = ServiceConstants.TASK_LIST_TEMPLATE_TYPE;
                    taskListInformation.Path = matterSettings.TitleListsPath + matter.MatterGuid + matterSettings.TaskNameSuffix;
                    if (matterRepositoy.CreateList(clientContext, taskListInformation))
                    {
                        matterRepositoy.BreakPermission(clientContext, taskListName, isCopyRoleAssignment);
                    }
                    else
                    {
                        return ServiceUtility.GenericResponse(errorSettings.ErrorCodeAddTaskList, errorSettings.ErrorMessageAddTaskList);
                    }
                }

                string oneNoteUrl = string.Concat(clientUrl.AbsolutePath, ServiceConstants.FORWARD_SLASH,
                    matter.MatterGuid, matterSettings.OneNoteLibrarySuffix, ServiceConstants.FORWARD_SLASH, matterOneNoteTitle);
                matterRepositoy.AddOneNote(clientContext, client.Url, oneNoteUrl, matter.MatterGuid, matter.Name);
                if (null != matter.Conflict)
                {
                    //Break permission for Matter library
                    matterRepositoy.BreakPermission(clientContext, matter.Name, isCopyRoleAssignment);

                    //Break permission for OneNote document library
                    string oneNoteLibraryName = string.Concat(matter.Name, matterSettings.OneNoteLibrarySuffix);
                    matterRepositoy.BreakPermission(clientContext, oneNoteLibraryName, isCopyRoleAssignment);
                }

                genericResponseVM = validationFunctions.RoleCheck(matter);
                if (genericResponseVM == null)
                {
                    string centralList = Convert.ToString(centralListURL, CultureInfo.InvariantCulture);
                    string matterSiteURL = centralList.Substring(0, centralList.LastIndexOf(string.Concat(ServiceConstants.FORWARD_SLASH,
                        ServiceConstants.LISTS, ServiceConstants.FORWARD_SLASH), StringComparison.OrdinalIgnoreCase));
                    string matterListName = centralList.Substring(centralList.LastIndexOf(ServiceConstants.FORWARD_SLASH, StringComparison.OrdinalIgnoreCase) + 1);

                    if(generalSettings.IsBackwardCompatible==false)
                    {
                        bool isMatterSaved = matterRepositoy.SaveMatter(client, matter, matterListName, matterConfiguration, matterSiteURL);
                        if (isMatterSaved == false)
                        {
                            genericResponseVM = ServiceUtility.GenericResponse(errorSettings.ErrorCodeAddTaskList, "Matter Not Saved");
                            genericResponseVM.IsError = true;
                            return genericResponseVM;
                        }
                    }

                    
                }
                genericResponseVM = new GenericResponseVM()
                {
                    Code = HttpStatusCode.OK.ToString(),
                    Value = client.Url,
                    IsError = false
                };
                return genericResponseVM;
            }
            catch (Exception ex)
            {
                throw;
            }
        }