/// <summary> /// Creates a new Redmine object. /// </summary> /// <typeparam name="T">The type of object to create.</typeparam> /// <param name="obj">The object to create.</param> /// <param name="ownerId">The owner identifier.</param> /// <returns></returns> /// <exception cref="RedmineException"></exception> /// <remarks> /// When trying to create an object with invalid or missing attribute parameters, you will get a 422 Unprocessable /// Entity response. That means that the object could not be created. /// </remarks> /// <code> /// <example> /// var project = new Project(); /// project.Name = "test"; /// project.Identifier = "the project identifier"; /// project.Description = "the project description"; /// redmineManager.CreateObject(project); /// </example> /// </code> public T CreateObject <T>(T obj, string ownerId) where T : class, new() { var url = UrlHelper.GetCreateUrl <T>(this, ownerId); var data = RedmineSerializer.Serialize(obj, MimeFormat); return(WebApiHelper.ExecuteUpload <T>(this, url, HttpVerbs.POST, data, "CreateObject")); }
/// <summary> /// Updates a Redmine object. /// </summary> /// <typeparam name="T">The type of object to be update.</typeparam> /// <param name="id">The id of the object to be update.</param> /// <param name="obj">The object to be update.</param> /// <param name="projectId">The project identifier.</param> /// <exception cref="RedmineException"></exception> /// <remarks> /// When trying to update an object with invalid or missing attribute parameters, you will get a /// 422(RedmineException) Unprocessable Entity response. That means that the object could not be updated. /// </remarks> /// <code></code> public void UpdateObject <T>(string id, T obj, string projectId) where T : class, new() { var url = UrlHelper.GetUploadUrl(this, id, obj, projectId); var data = RedmineSerializer.Serialize(obj, MimeFormat); data = Regex.Replace(data, @"\r\n|\r|\n", "\r\n"); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.PUT, data, "UpdateObject"); }
/// <summary> /// Updates the attachment. /// </summary> /// <param name="issueId">The issue identifier.</param> /// <param name="attachment">The attachment.</param> public void UpdateAttachment(int issueId, Attachment attachment) { var address = UrlHelper.GetAttachmentUpdateUrl(this, issueId); var attachments = new Attachments { { attachment.Id, attachment } }; var data = RedmineSerializer.Serialize(attachments, MimeFormat); WebApiHelper.ExecuteUpload(this, address, HttpVerbs.PATCH, data, "UpdateAttachment"); }
/// <summary> /// Creates or updates a wiki page. /// </summary> /// <param name="projectId">The project id or identifier.</param> /// <param name="pageName">The wiki page name.</param> /// <param name="wikiPage">The wiki page to create or update.</param> /// <returns></returns> public WikiPage CreateOrUpdateWikiPage(string projectId, string pageName, WikiPage wikiPage) { var result = RedmineSerializer.Serialize(wikiPage, MimeFormat); if (string.IsNullOrEmpty(result)) { return(null); } var url = UrlHelper.GetWikiCreateOrUpdaterUrl(this, projectId, pageName); return(WebApiHelper.ExecuteUpload <WikiPage>(this, url, HttpVerbs.PUT, result, "CreateOrUpdateWikiPage")); }
/// <summary> /// Deletes the Redmine object. /// </summary> /// <typeparam name="T">The type of objects to delete.</typeparam> /// <param name="id">The id of the object to delete</param> /// <param name="parameters">The parameters</param> /// <exception cref="RedmineException"></exception> /// <code></code> public void DeleteObject <T>(string id, NameValueCollection parameters = null) where T : class, new() { var url = UrlHelper.GetDeleteUrl <T>(this, id); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.DELETE, string.Empty, "DeleteObject", parameters); }
/// <summary> /// Deletes a wiki page, its attachments and its history. If the deleted page is a parent page, its child pages are not /// deleted but changed as root pages. /// </summary> /// <param name="projectId">The project id or identifier.</param> /// <param name="pageName">The wiki page name.</param> public void DeleteWikiPage(string projectId, string pageName) { var url = UrlHelper.GetDeleteWikirUrl(this, projectId, pageName); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.DELETE, string.Empty, "DeleteWikiPage"); }
/// <summary> /// Removes an user from a group. /// </summary> /// <param name="groupId">The group id.</param> /// <param name="userId">The user id.</param> public void RemoveUserFromGroup(int groupId, int userId) { var url = UrlHelper.GetRemoveUserFromGroupUrl(this, groupId, userId); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.DELETE, string.Empty, "DeleteUser"); }
/// <summary> /// Adds an existing user to a group. /// </summary> /// <param name="groupId">The group id.</param> /// <param name="userId">The user id.</param> public void AddUserToGroup(int groupId, int userId) { var url = UrlHelper.GetAddUserToGroupUrl(this, groupId); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.POST, DataHelper.UserData(userId, MimeFormat), "AddUser"); }
/// <summary> /// Removes the watcher from issue. /// </summary> /// <param name="issueId">The issue identifier.</param> /// <param name="userId">The user identifier.</param> public void RemoveWatcherFromIssue(int issueId, int userId) { var url = UrlHelper.GetRemoveWatcherUrl(this, issueId, userId); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.DELETE, string.Empty, "RemoveWatcher"); }
/// <summary> /// Adds the watcher to issue. /// </summary> /// <param name="issueId">The issue identifier.</param> /// <param name="userId">The user identifier.</param> public void AddWatcherToIssue(int issueId, int userId) { var url = UrlHelper.GetAddWatcherUrl(this, issueId, userId); WebApiHelper.ExecuteUpload(this, url, HttpVerbs.POST, DataHelper.UserData(userId, MimeFormat), "AddWatcher"); }