using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Comal.Classes; using InABox.Core; using Xamarin.Forms; namespace comal.timesheets { public class AssignmentListDataModel : ListDataModel { public override Columns Columns => new Columns(x => x.ID) .Add(x => x.Number) .Add(x => x.Title) .Add(x => x.Description) .Add(x => x.Date) .Add(x => x.Actual.Start) .Add(x => x.Actual.Finish) .Add(x => x.Booked.Start) .Add(x => x.Booked.Finish) .Add(x => x.ActivityLink.Color) .Add(x => x.EmployeeLink.ID) .Add(x => x.JobLink.ID) .Add(x => x.JobLink.JobNumber) .Add(x => x.JobLink.Name) .Add(x => x.Task.ID) .Add(x => x.Task.Number) .Add(x => x.Task.Title) .Add(x => x.Completed); } public class AssignmentListDataModelItem : CoreDataModelItem { public Guid Id => Row.Get(c => c.ID); public int Number => Row.Get(c => c.Number); public Guid EmployeeId => Row.Get(c => c.EmployeeLink.ID); public Guid JobID => Row.Get(c => c.JobLink.ID); public string JobNumber => Row.Get(c => c.JobLink.JobNumber); public string JobName => Row.Get(c => c.JobLink.Name); public Guid TaskID => Row.Get(c => c.Task.ID); public int TaskNumber => Row.Get(c => c.Task.Number); public string TaskName => Row.Get(c => c.Task.Title); public String Subject => string.Format("{0}{1} {2}", Row.Get(c => c.Number), Row.Get(c => c.JobLink.ID) != Guid.Empty ? $"({Row.Get(c => c.JobLink.JobNumber)})" : "", Row.Get(c => c.Title)); public string Notes => Row.Get(c => c.Description); public DateTime StartTime { get { var startspan = Row.Get(c => c.Actual.Start); if (startspan.TotalMinutes != 0) return Row.Get(c => c.Date).Add(Row.Get(c => c.Actual.Start)); else return Row.Get(c => c.Date).Add(Row.Get(c => c.Booked.Start)); } } public DateTime EndTime { get { var finishspan = Row.Get(c => c.Actual.Finish); if (finishspan.TotalMinutes != 0) return Row.Get(c => c.Date).Add(Row.Get(c => c.Actual.Finish)); else return Row.Get(c => c.Date).Add(Row.Get(c => c.Booked.Finish)); } } public bool Completed => !Row.Get(c => c.Completed).IsEmpty(); public Color Color { get { var color = Row.Get(c => c.ActivityLink.Color); return !String.IsNullOrWhiteSpace(color) ? Color.FromHex(color) : Color.Silver; } set { Row.Set(c => c.ActivityLink.Color, value.ToHex()); } } public Color TextColor => Color.Black; public ObservableCollection ResourceIds => new ObservableCollection() { Row.Get(c => c.EmployeeLink.ID) }; } }