public string CreateDocumentEntity(string itemUrl, string editUrl, int userId = 0) { if (String.IsNullOrWhiteSpace(itemUrl)) { return(null); } if (userId == 0) { userId = SPContext.Current.Web.CurrentUser.ID; } SPFolder spFolder = SpList.ParentWeb.GetFolder(itemUrl); DateTime created = DateTime.Now; long barcodelong = 0; if (spFolder.Item[Constants.BarCodeFieldName] != null) { var barcodeValue = spFolder.Item[Constants.BarCodeFieldName].ToString(); BarcodeFabric.TryParse(barcodeValue, out barcodelong); } var barval = barcodelong > 0 ? barcodelong.ToString() : null; StatusValuePair <ArchiveEntities> archiveElement = _archiveEntityCrud.Create(itemUrl, editUrl, userId, spFolder.Item.ParentList.ID.ToString(), spFolder.Item.ID.ToString("D"), created, barode: barval); if (!archiveElement.HasValue) { return(null); } string barcode = archiveElement.Value.Barcode; // записываем права для автора List <Permissions> permissions = new List <Permissions>(1); string author = spFolder.Item.TryGetFieldValue(SPBuiltInFieldId.Author, string.Empty); if (!string.IsNullOrWhiteSpace(author)) { SPFieldUserValue authorUserValue = new SPFieldUserValue(SpList.ParentWeb, author); Permissions authorPermission = new Permissions { Barcode = barcode, CanWrite = true, UserGroupId = authorUserValue.User.ID }; permissions.Add(authorPermission); } CreateOrUpdatePermissions(permissions); return(barcode); }
public ArchiveEntities CreateArchiveElement(SPFolder folder, string documentType = null, string description = null, string status = null) { if (folder == null || folder.Item == null || folder.Item[SPBuiltInFieldId.Author] == null) { return(null); } SPFieldUserValue author = new SPFieldUserValue(folder.Item.Web, folder.Item[SPBuiltInFieldId.Author].ToString()); int userId = author.User.ID; DateTime created = DateTime.Now; // создаём новую запись в БД, генерируем название папки из Id новой записи string editUrl = folder.Item.ParentList.DefaultEditFormUrl + "?ID=" + folder.Item.ID + "&RootFolder=/" + (folder.Item.Folder == null ? string.Empty : folder.Item.Folder.Url); long barcode = 0; if (folder.Item[Constants.BarCodeFieldName] != null) { var barcodeValue = folder.Item[Constants.BarCodeFieldName].ToString(); BarcodeFabric.TryParse(barcodeValue, out barcode); } StatusValuePair <ArchiveEntities> archiveElement = _archiveEntityCrud.Create(folder.Url, editUrl, userId, folder.Item.ParentList.ID.ToString(), folder.Item.ID.ToString("D"), created, true, documentType, description, status, barcode > 0 ? barcode.ToString() : null); if (!archiveElement.HasValue) { return(null); } using (DisabledItemEventsScope scope = new DisabledItemEventsScope()) { folder.Item[Constants.BarCodeFieldName] = archiveElement.Value.Barcode; folder.Item.Update(); } List <Permissions> permissions = PermissionsHelper.GetPermissions(archiveElement.Value.Barcode, folder.Item); CreateOrUpdatePermissions(permissions); return(archiveElement); }