protected override Resource ConvertToIssueTracker(ProjectResource project) { Resource p = new Resource(); if (!MasonBuilderContext.PreferMinimalResponse) { p.Meta.Title = "Project"; p.Meta.Description = "This resource represents a single project with its data and related actions."; } Uri selfUrl = typeof(ProjectResource).CreateUri(new { id = project.Project.Id }); Control selfLink = MasonBuilderContext.NewLink("self", selfUrl); p.AddControl(selfLink); Uri issuesUrl = typeof(ProjectIssuesResource).CreateUri(new { id = project.Project.Id }); Control issuesLink = MasonBuilderContext.NewLink(RelTypes.Issues, issuesUrl, "All issues in project"); p.AddControl(issuesLink); dynamic updateTemplate = new DynamicDictionary(); updateTemplate.Code = project.Project.Code; updateTemplate.Title = project.Project.Title; updateTemplate.Description = project.Project.Description; Control updateAction = MasonBuilderContext.NewJsonAction(RelTypes.ProjectUpdate, selfUrl, "Update project details", template: (DynamicDictionary)updateTemplate); p.AddControl(updateAction); Uri addIssueSchemaUrl = typeof(SchemaTypeResource).CreateUri(new { name = "create-issue" }); Control addIssueAction = MasonBuilderContext.NewJsonFilesAction(RelTypes.ProjectAddIssue, issuesUrl, "args", "Add issue", "Add new issue to project", schemaUrl: addIssueSchemaUrl); if (!MasonBuilderContext.PreferMinimalResponse) { addIssueAction.AddFile(new FileDefinition { name = "attachment", title = "Attachment", description = "Include attachment for new issue." }); } p.AddControl(addIssueAction); Control deleteAction = MasonBuilderContext.NewVoidAction(RelTypes.ProjectDelete, selfUrl, "Delete project", "This will delete the whole project and all issues in it.", method: "DELETE"); p.AddControl(deleteAction); ((dynamic)p).Id = project.Project.Id; ((dynamic)p).Code = project.Project.Code; ((dynamic)p).Title = project.Project.Title; ((dynamic)p).Description = project.Project.Description; return(p); }
public object Get() { Resource common = new Resource(); Uri selfUri = typeof(ResourceCommonResource).CreateUri(); Control selfLink = MasonBuilderContext.NewLink("self", selfUri); common.AddControl(selfLink); Uri contactUri = typeof(ContactResource).CreateUri(); Control contactLink = MasonBuilderContext.NewLink(RelTypes.Contact, contactUri, "Contact information"); contactLink.description = "Complete contact information in standard formats such as vCard and jCard."; common.AddControl(contactLink); Uri logoUri = new Uri(CommunicationContext.ApplicationBaseUri.EnsureHasTrailingSlash(), "Origins/JoeHacker/logo.png"); Control logoLink = MasonBuilderContext.NewLink(RelTypes.Logo, logoUri); common.AddControl(logoLink); if (!MasonBuilderContext.PreferMinimalResponse) { common.Meta.Title = "Common resource data for " + Settings.OriginName; common.Meta.Description = "This resource contains common information for all resources (such as common links, implementation and owner details)."; } Uri projectsUri = typeof(ProjectCollectionResource).CreateUri(); Control projectsLink = MasonBuilderContext.NewLink(RelTypes.Projects, projectsUri, "List all projects"); common.AddControl(projectsLink); common.AddControl(MasonBuilderContext.BuildIssueQueryTemplate(CommunicationContext)); Uri projectsUrl = typeof(ProjectCollectionResource).CreateUri(); Uri createProjectSchemaUrl = typeof(SchemaTypeResource).CreateUri(new { name = "create-project" }); Control addProjectAction = MasonBuilderContext.NewJsonAction(RelTypes.ProjectAdd, projectsUrl, "Create project", "Add new project to issue tracker.", schemaUrl: createProjectSchemaUrl); common.AddControl(addProjectAction); return(new ResourceCommonResource { Value = common }); }
protected override Resource ConvertToIssueTracker(IssueResource issue) { Resource i = new Resource(); if (!MasonBuilderContext.PreferMinimalResponse) { i.Meta.Title = "Issue"; i.Meta.Description = "This resource represents a single issue with its data and related actions."; } Uri selfUrl = typeof(IssueResource).CreateUri(new { id = issue.Issue.Id }); Control selfLink = MasonBuilderContext.NewLink("self", selfUrl); i.AddControl(selfLink); Uri projectUrl = typeof(ProjectResource).CreateUri(new { id = issue.Issue.OwnerProject.Id }); Control projectLink = MasonBuilderContext.NewLink("up", projectUrl, "Containing project"); i.AddControl(projectLink); Uri attachmentsUrl = typeof(IssueAttachmentsResource).CreateUri(new { id = issue.Issue.Id }); Control attachmentsLink = MasonBuilderContext.NewLink(RelTypes.Attachments, attachmentsUrl, "All attachments for this issue"); i.AddControl(attachmentsLink); dynamic updateTemplate = new DynamicDictionary(); updateTemplate.Title = issue.Issue.Title; updateTemplate.Description = issue.Issue.Description; updateTemplate.Severity = issue.Issue.Severity; Control updateAction = MasonBuilderContext.NewJsonAction(RelTypes.IssueUpdate, selfUrl, "Update issue details", template: (DynamicDictionary)updateTemplate); i.AddControl(updateAction); Control deleteAction = MasonBuilderContext.NewVoidAction(RelTypes.IssueDelete, selfUrl, "Delete issue", method: "DELETE"); i.AddControl(deleteAction); Uri addAttachmentSchemaUrl = typeof(SchemaTypeResource).CreateUri(new { name = "create-attachment" }); Control addAttachmentAction = MasonBuilderContext.NewJsonFilesAction(RelTypes.IssueAddAttachment, attachmentsUrl, "args", "Add new attachment to issue", schemaUrl: addAttachmentSchemaUrl); if (!MasonBuilderContext.PreferMinimalResponse) { addAttachmentAction.AddFile(new FileDefinition { name = "attachment", title = "Attachment for issue" }); } i.AddControl(addAttachmentAction); ((dynamic)i).ID = issue.Issue.Id; ((dynamic)i).Title = issue.Issue.Title; ((dynamic)i).Description = issue.Issue.Description; ((dynamic)i).Severity = issue.Issue.Severity; List <SubResource> attachments = new List <SubResource>(); foreach (Attachment att in issue.Attachments) { dynamic a = new SubResource(); a.Id = att.Id; a.Title = att.Title; Uri attachmentUrl = typeof(AttachmentResource).CreateUri(new { id = att.Id }); Control attachmentLink = MasonBuilderContext.NewLink("self", attachmentUrl); a.AddControl(attachmentLink); Uri contentUrl = typeof(AttachmentContentResource).CreateUri(new { id = att.Id }); Control contentLink = MasonBuilderContext.NewLink(RelTypes.AttachmentContent, contentUrl, "Download content", att.ContentType); a.AddControl(contentLink); attachments.Add(a); } ((dynamic)i).Attachments = attachments; return(i); }