Last active
November 3, 2016 21:23
-
-
Save TimGeyssens/cff7e3ea5a31849cc71407ba1b6b4886 to your computer and use it in GitHub Desktop.
Sample integration of UI-O-Matic with Github, showing the power of custom repositories (making use of https://github.com/octokit/octokit.net for the heavy lifting)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
using UIOMatic.Attributes; | |
using UIOMatic.Example.GitHubIssues.Repo; | |
using Umbraco.Core.Persistence.DatabaseAnnotations; | |
namespace UIOMatic.Example.GitHubIssues.Models | |
{ | |
[UIOMatic("issues", "Issues", "Issue", | |
RepositoryType = typeof(GitHubIssuesRepo), | |
ShowOnSummaryDashboard = true)] | |
public class Issue | |
{ | |
[PrimaryKeyColumn] | |
public int Id { get; set; } | |
[Required] | |
[UIOMaticField(IsNameField = true)] | |
[UIOMaticListViewField] | |
public string Title { get; set; } | |
[UIOMaticField(View = UIOMatic.Constants.FieldEditors.Textarea)] | |
public string Body { get; set; } | |
public override string ToString() | |
{ | |
return Title; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Octokit; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using UIOMatic.Data; | |
using UIOMatic.Models; | |
namespace UIOMatic.Example.GitHubIssues.Repo | |
{ | |
public class GitHubIssuesRepo : AbstractUIOMaticRepository<Models.Issue, int> | |
{ | |
private const string RepoOwner = "TimGeyssens"; | |
private const string RepoName = "UIOMatic"; | |
private GitHubClient Client | |
{ | |
get | |
{ | |
var client = new GitHubClient(new ProductHeaderValue("my-cool-app")); | |
var basicAuth = new Credentials("USERNAME", "PASSWORD"); | |
client.Credentials = basicAuth; | |
return client; | |
} | |
} | |
public override Models.Issue Create(Models.Issue entity) | |
{ | |
var createIssue = new NewIssue(entity.Title); | |
createIssue.Body = entity.Body; | |
var issue = Client.Issue.Create(RepoOwner, RepoName, createIssue).Result; | |
entity.Id = issue.Number; | |
return entity; | |
} | |
public override void Delete(int[] ids) | |
{ | |
foreach (var id in ids) | |
{ | |
var issue = Client.Issue.Get(RepoOwner, RepoName, id).Result; | |
var update = issue.ToUpdate(); | |
update.State = ItemState.Closed; | |
var updatedIssue = Client.Issue.Update(RepoOwner, RepoName, issue.Number, update).Result; | |
} | |
} | |
public override Models.Issue Get(int id) | |
{ | |
var issue = Client.Issue.Get(RepoOwner, RepoName, id).Result; | |
return new Models.Issue | |
{ | |
Id = issue.Number, | |
Title = issue.Title, | |
Body = issue.Body | |
}; | |
} | |
public override IEnumerable<Models.Issue> GetAll(string sortColumn = "", string sortOrder = "") | |
{ | |
var retVal = new List<Models.Issue>(); | |
var issues = Client.Issue.GetAllForRepository(RepoOwner, RepoName).Result; | |
foreach(var issue in issues) | |
{ | |
retVal.Add(new Models.Issue | |
{ | |
Id = issue.Number, | |
Title = issue.Title | |
}); | |
} | |
return retVal; | |
} | |
public override UIOMaticPagedResult<Models.Issue> GetPaged(int pageNumber, int itemsPerPage, string searchTerm = "", IDictionary<string, string> filters = null, string sortColumn = "", string sortOrder = "") | |
{ | |
//used in the ListView but we aren't using that one currently | |
throw new NotImplementedException(); | |
} | |
public override long GetTotalRecordCount() | |
{ | |
return GetAll().Count(); | |
} | |
public override Models.Issue Update(Models.Issue entity) | |
{ | |
var issue = Client.Issue.Get(RepoOwner, RepoName, entity.Id).Result.ToUpdate(); | |
issue.Title = entity.Title; | |
issue.Body = entity.Body; | |
var updatedIssue = Client.Issue.Update(RepoOwner, RepoName, entity.Id, issue).Result; | |
return entity; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment