Beispiel #1
0
        public ArchiveEntities CreateArchiveElement(string documentBarcode, string documentType = null, string description = null, string status = null)
        {
            int      userId  = SPContext.Current.Web.CurrentUser.ID;
            DateTime created = DateTime.Now;

            // создаём новую запись в БД, генерируем название папки из Id новой записи
            StatusValuePair <ArchiveEntities> archiveElement = _archiveEntityCrud.Create(string.Empty, string.Empty, userId, null, null, created, true, documentType, description, status);

            if (!archiveElement.HasValue)
            {
                return(null);
            }

            // создаём папку с именем = id новой записи
            SPContentType contentType = SpList.ParentWeb.ContentTypes.Cast <SPContentType>().FirstOrDefault(c => c.Name == Navicon.SP.SqlCache.Common.Box.WebRoot.ContentTypes.DocumentElement);

            if (contentType == null)
            {
                return(null);
            }

            Dictionary <string, object> fieldValues = new Dictionary <string, object>
            {
                { "ContentTypeId", contentType.Id },
                { Constants.BarCodeFieldName, archiveElement.Value.Barcode }
            };

            foreach (SPField field in contentType.Fields)
            {
                if (!string.IsNullOrWhiteSpace(field.DefaultValue))
                {
                    fieldValues.Add(field.InternalName, field.DefaultValue);
                }
            }

            SPFolder    folder           = null;
            SPUserToken currentUserToken = SPContext.Current.Web.CurrentUser.UserToken;

            folder = SpList.CreateSubFolderIfNotExists(SPContext.Current.Web.CurrentUser.ID + "_" + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - 1412440895000), fieldValues: fieldValues, userToken: currentUserToken);
            if (folder == null)
            {
                Logger.ShowErrorOnPage("Не удалось создать элемент архива.",
                                       "Navicon.SP.Components.Archive.ArchiveProvider.CreateArchiveElement()");
                return(null);
            }

            // обновляем url и данные списка и элемента
            string editUrl = folder.Item.ParentList.DefaultEditFormUrl + "?ID=" + folder.Item.ID + "&RootFolder=/" + (folder.Item.Folder == null ? string.Empty : folder.Item.Folder.Url);

            archiveElement = _archiveEntityCrud.UpdateFolderUrlBarcode(archiveElement.Value.Barcode, folder, editUrl);

            // записываем уровни доступа
            List <Permissions> permissions = PermissionsHelper.GetPermissions(archiveElement.Value.Barcode, folder.Item);

            CreateOrUpdatePermissions(permissions);

            StatusValuePair <ArchiveEntities> docEntity = _archiveEntityCrud.GetByBarcode(documentBarcode);

            if (docEntity.HasValue)
            {
                _manyToManyEntityCrud.Create(docEntity.Value.Id, archiveElement.Value.Id);
                return(archiveElement);
            }

            return(null);
        }