public Person Build() { if (Id == null) throw new InvalidOperationException($"{nameof(Id)} is null."); if (Name == null) throw new InvalidOperationException($"{nameof(Name)} is null."); if (Schedule == null) throw new InvalidOperationException($"{nameof(Schedule)} is null."); if (DayOfWeekDismisses == null) throw new InvalidOperationException($"{nameof(DayOfWeekDismisses)} is null."); if (TemporaryDismisses == null) throw new InvalidOperationException($"{nameof(TemporaryDismisses)} is null."); var person = new Person(Id, Name, Role, Schedule, DayOfWeekDismisses, TemporaryDismisses); return person; }
public static string ProcessPerson(Person p, BusinessDay[] days, string delimiter) { TemporaryDismissCollection temporaryDismisses; if (!RepositoryManager.TryGet(p.Identifier, out temporaryDismisses)) temporaryDismisses = new TemporaryDismissCollection(p.Identifier, Array.Empty<TemporaryDismiss>()); DayOfWeekDismissCollection dayOfWeekDismisses; if (!RepositoryManager.TryGet(p.Identifier, out dayOfWeekDismisses)) dayOfWeekDismisses = new DayOfWeekDismissCollection(p.Identifier, Array.Empty<DayOfWeekDismiss>()); var builder = new StringBuilder(days.Length * 3); builder.Append(p.Identifier); builder.Append(delimiter); builder.Append(p.Name); builder.Append(delimiter); foreach (var day in days) { if (dayOfWeekDismisses.Any(dismiss => dismiss.GetDismissStatus(day.Identifier.Date).Dismissed) || temporaryDismisses.Any(dismiss => dismiss.GetDismissStatus(day.Identifier.Date).Dismissed)) { builder.Append(DismissedLetter); builder.Append(delimiter); continue; } else if (day.Contains(p.Identifier)) { builder.Append(AttendedLetter); builder.Append(delimiter); continue; } else { builder.Append(UnattendedLetter); builder.Append(delimiter); } } return builder.ToString(); }
public static Person[] DeserializePersonCollection(IEnumerable<string> lines, string delimiter) { if (lines == null) throw new ArgumentNullException(nameof(lines)); var linesArray = lines.Where(line => !line.Equals(string.Empty) && !line.Equals(Environment.NewLine)).ToArray(); var people = new Person[linesArray.Length]; for (int i = 0; i < linesArray.Length; i++) { var line = linesArray[i]; var parameters = line.Split(delimiter.ToArray(), StringSplitOptions.None); if (parameters.Length != 2) throw new ArgumentException($"Line {i} is poorly formated. Expected 2 elements, found {parameters.Length}."); var identifier = parameters[0]; var name = parameters[1].Replace(Environment.NewLine, string.Empty); var person = new Person(new PersonIdentifier(identifier), name); people[i] = person; } return people; }
public bool Equals(Person other) { if (other == null) return false; if (!other.Role.Equals(other.Role)) return false; if (!Identifier.Document.Equals(other.Identifier.Document)) return false; if (!Name.Equals(other.Name)) return false; if (!Schedule.Equals(other.Schedule)) return false; var uniqueDayOfWeekDismisses = new HashSet<DayOfWeekDismiss>(DayOfWeekDismisses); if (!uniqueDayOfWeekDismisses.SetEquals(other.DayOfWeekDismisses)) return false; var uniqueTemporaryDismisses = new HashSet<TemporaryDismiss>(TemporaryDismisses); if (!uniqueTemporaryDismisses.SetEquals(other.TemporaryDismisses)) return false; return true; }
public void TestInitialize() { Reference = new Person(new PersonIdentifier("012344__3"), "John Doe"); }
public static bool TryGet(PersonIdentifier id, out Person entity) => PersonRepository.TryGet(id, out entity);
public static void Save(Person entity) => PersonRepository.Save(entity);