123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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<Assignment, AssignmentListDataModelItem>
- {
- public override Columns<Assignment> Columns => new Columns<Assignment>(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<Assignment, Guid>(c => c.ID);
- public int Number => Row.Get<Assignment, int>(c => c.Number);
- public Guid EmployeeId => Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID);
- public Guid JobID => Row.Get<Assignment, Guid>(c => c.JobLink.ID);
- public string JobNumber => Row.Get<Assignment, String>(c => c.JobLink.JobNumber);
- public string JobName => Row.Get<Assignment, String>(c => c.JobLink.Name);
- public Guid TaskID => Row.Get<Assignment, Guid>(c => c.Task.ID);
- public int TaskNumber => Row.Get<Assignment, int>(c => c.Task.Number);
- public string TaskName => Row.Get<Assignment, String>(c => c.Task.Title);
- public String Subject => string.Format("{0}{1} {2}",
- Row.Get<Assignment, int>(c => c.Number),
- Row.Get<Assignment, Guid>(c => c.JobLink.ID) != Guid.Empty
- ? $"({Row.Get<Assignment, String>(c => c.JobLink.JobNumber)})"
- : "",
- Row.Get<Assignment, String>(c => c.Title));
- public string Notes => Row.Get<Assignment, String>(c => c.Description);
- public DateTime StartTime
- {
- get
- {
- var startspan = Row.Get<Assignment, TimeSpan>(c => c.Actual.Start);
- if (startspan.TotalMinutes != 0)
- return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Actual.Start));
- else
- return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Booked.Start));
- }
- }
- public DateTime EndTime
- {
- get
- {
- var finishspan = Row.Get<Assignment, TimeSpan>(c => c.Actual.Finish);
- if (finishspan.TotalMinutes != 0)
- return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Actual.Finish));
- else
- return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Booked.Finish));
- }
- }
- public bool Completed => !Row.Get<Assignment, DateTime>(c => c.Completed).IsEmpty();
- public Color Color
- {
- get
- {
- var color = Row.Get<Assignment, String>(c => c.ActivityLink.Color);
- return !String.IsNullOrWhiteSpace(color)
- ? Color.FromHex(color)
- : Color.Silver;
- }
- set { Row.Set<Assignment, String>(c => c.ActivityLink.Color, value.ToHex()); }
- }
- public Color TextColor => Color.Black;
- public ObservableCollection<object> ResourceIds => new ObservableCollection<object>() { Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID) };
- }
- }
|