/// <summary> /// Creates an external link. /// </summary> public ExternalLink CreateExternalLink(ExternalLink externalLink, string webUrl, string accessToken) { try { return(_externalLinksRepository.Create(webUrl, accessToken, externalLink)); } catch (Exception) { throw new Exception("An error occured while creating the link"); } }
/// <summary> /// Creates the group. /// </summary> /// <param name="itemRequestModel">The item request model containing a valid group to create.</param> /// <param name="webUrl">The web URL.</param> /// <param name="accessToken">The access token.</param> /// <param name="currentUserEmail"></param> /// <param name="isUserAdmin">Boolean flag for whether user is an admin</param> /// <returns></returns> public override Group Create(ItemRequestModel itemRequestModel, string webUrl, string accessToken, string currentUserEmail, bool isUserAdmin) { // User cannot create a group in a group they do not own //if(groupRequest.Parent != null && !IsOwnerOrDesignee(groupRequest.Parent)) // throw new Exception("You cannot create a group in a group you do not own."); // Non-admin cannot create a clause in a locked group if (itemRequestModel.Parent != null && itemRequestModel.Parent.IsLocked && !isUserAdmin) { throw new Exception("You cannot modify a locked group."); } try { var createdGroup = _groupRepository.Create(webUrl, accessToken, itemRequestModel.Group); // need to explicitly retrieve the new group in order to get its full set of properties var retrievedNewGroup = _groupRepository.Get(webUrl, createdGroup.Id, accessToken, SpApiConstants.Lists.GROUP_EXPAND); return (BuildGroups(new List <Group> { retrievedNewGroup }, webUrl, accessToken, currentUserEmail, isUserAdmin) .First()); } catch (Exception) { throw new Exception("Failed to create group"); } }
private Clause ProcessTags(Clause clause, string webUrl, string accessToken) { // watch for null pointer exception if (clause.TagsList == null) { clause.TagsList = new List <Tag>(); } var storedTags = _tagRepository.GetAll(webUrl, accessToken, ""); // Create new tags, if any; ensure there are no tags with the same title in SharePoint var createdTags = clause.TagsList .Where(t => t.Id <= 0 && storedTags.All(storedTag => storedTag.Title != t.Title)) .Select(tag => _tagRepository.Create(webUrl, accessToken, tag)).ToList(); // concatenate any newly created tags onto the list of existing tags; will be an empty list // if their are neither var existingTagList = clause.TagsList.Where(t => t.Id > 0); clause.TagsList = new List <Tag>(createdTags.Concat(existingTagList)); // Update clause.Tags to match the TagsList; regardless of whether an add, remove, or both // occur, this will ensure the clause.Tag stays current; will be an empty string if no tags clause.Tags = string.Join(",", clause.TagsList.Select(t => t.Id)); return(clause); }
private void ProcessExternalLinks(Clause clause, List <ExternalLink> externalLinks, string webUrl, string accessToken) { // create new external links if needed if (!externalLinks.Any()) { return; } var externalLinksToCreate = externalLinks.Where(externalLink => externalLink.Id < 0); foreach (var externalLink in externalLinksToCreate) { externalLink.ClauseId = clause.Id; _externalLinksRepository.Create(webUrl, accessToken, externalLink); } }
/// <summary> /// Creates the clause (and optionally a group). /// </summary> public override Clause Create(ItemRequestModel itemRequestModel, string webUrl, string accessToken, string currentUserEmail, bool isUserAdmin) { // User cannot create a clause in a group they do not own //if(clauseRequest.Group != null && !IsOwnerOrDesignee(clauseRequest.Group)) // throw new Exception("You cannot create a clause in a group you do not own."); // Non-admin cannot create a clause in a locked group if (itemRequestModel.Group != null && itemRequestModel.Group.IsLocked && !isUserAdmin) { throw new Exception("You cannot modify a locked group"); } try { var preparedClause = PrepareClause(itemRequestModel, webUrl, accessToken); var createdClause = _clauseRepository.Create(webUrl, accessToken, preparedClause); // need to explicitly retrieve the new clause in order to get its full set of properties var retrievedNewClause = _clauseRepository.Get(webUrl, createdClause.Id, accessToken, SpApiConstants.Lists.CLAUSE_EXPAND); // now that the clause has been created, create any new external links; there is a dependency // on the clause id (which is not set before the clause is created) ProcessExternalLinks(retrievedNewClause, itemRequestModel.ExternalLinks, webUrl, accessToken); return (BuildClauses(new List <Clause> { retrievedNewClause }, webUrl, accessToken, currentUserEmail, isUserAdmin).First()); } catch (Exception e) { throw new Exception("Failed to create clause", e); } }
public virtual T Post(string webUrl, [FromBody] T item, string accessToken = "") { accessToken = GetAccessToken(accessToken); item.ToClient = false; return(Repository.Create(webUrl, accessToken, item)); }