private Data GetReadData(string id, Worker worker) { Data data = new Data() { Name = "worker", Url = new System.Uri(Request.Headers.Host + "/api/worker/" + id) }; data.Rel = new List<string>(); data.Rel.Add("item"); data.Rel.Add(Request.Headers.Host + "/api/rels/worker"); List<Data> children = new List<Data>(); children.Add(new Data { Name = "number", Label = "Number" , Value = worker == null ? null : worker.number}); children.Add(new Data { Name = "firstName", Label = "First Name", Value = worker == null ? null : worker.firstName }); children.Add(new Data { Name = "lastName", Label = "Last Name", Value = worker == null ? null : worker.lastName }); children.Add(new Data { Name = "last4SSN", Label = "Last 4 digits of SSN", Value = worker == null ? null : worker.last4SSN }); children.Add(new Data { Name = "dob", Label = "Date Of Birth", Value = worker == null ? null : worker.dob.ToString() }); children.Add(new Data { Name = "status", Label = "Status", Value = worker == null ? null : worker.status }); children.Add(new Data { Name = "avatarUrl", Transclude = "true", Url = new System.Uri("http://example.org/avatars/{number}"), Value = "Worker Photo" }); data.Children = children; return data; }
private List<Data> GetDataElements(List<string> actions, string id, Worker worker, List<WorkerSkill> workerSkills) { List<Data> result = new List<Data>(); if(actions.Contains(Actions.Read)) { result.Add(GetReadData(id, worker)); if (!string.IsNullOrEmpty(id)) { if (null == workerSkills) { result.Add(GetSkillData(id, null)); } else { foreach (WorkerSkill s in workerSkills) { result.Add(GetSkillData(id, s)); } } } if (worker == null) { result.Add(GetSearchData()); } } if (actions.Contains(Actions.Append) && worker == null) { result.Add(GetActionData(string.Empty,Actions.Append)); } if (actions.Contains(Actions.Replace)) { result.Add(GetActionData(id, Actions.Replace)); } if (actions.Contains(Actions.Remove)) { result.Add(GetActionData(id, Actions.Remove)); } return result; }