Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
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;
}
}
}
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