/// <summary> /// Найти подпись по имени /// </summary> public ISignatureLibraryApp FindByFullName(string fullName, DepartmentTypeApp departmentType) => PersonsInformation.FindIndex(person => person.SurnameAndDepartmentEqual(fullName, departmentType)). WhereBad(foundIndex => foundIndex > -1, badFunc: _ => PersonsInformation.FindIndex(person => person.SurnameEqual(fullName))). WhereContinue(foundIndex => foundIndex > -1, okFunc: foundIndex => _signaturesLibrary.Values[foundIndex], badFunc: foundIndex => null);
public PersonInformationApp(string surname, string name, string patronymic, DepartmentTypeApp departmentType, Func <DepartmentTypeApp, string> departmentToString) { Surname = !surname.IsNullOrWhiteSpace() ? surname : throw new ArgumentNullException(nameof(surname)); Name = name ?? String.Empty; Patronymic = patronymic ?? String.Empty; DepartmentType = departmentType; _departmentToString = departmentToString ?? throw new ArgumentNullException(nameof(departmentToString)); }
/// <summary> /// Найти подписи по именам /// </summary> public IEnumerable <ISignatureLibraryApp> FindByFullNames(IEnumerable <string> fullNames, DepartmentTypeApp departmentType = DepartmentTypeApp.Unknown) => fullNames.Select(fullName => FindByFullName(fullName, departmentType)). Where(signature => signature != null);
/// <summary> /// Проверить отдел по его типу /// </summary> public DepartmentTypeApp CheckDepartmentAccordingToType(DepartmentTypeApp departmentType, PersonDepartmentType personDepartmentType) => personDepartmentType switch {
/// <summary> /// Найти подпись по имени или получить случайную /// </summary> public IResultAppValue <ISignatureLibraryApp> FindByFullNameOrRandom(string fullName, DepartmentTypeApp departmentType) => new ResultAppValue <ISignatureLibraryApp>(FindByFullName(fullName, departmentType), new ErrorApplication(ErrorApplicationType.SignatureNotFound, $"Подпись по имени {fullName} не найдена")). ResultValueBadBind(_ => new ResultAppValue <ISignatureLibraryApp>(GetRandomSignature(), new ErrorApplication(ErrorApplicationType.SignatureNotFound, "База подписей пуста")));
/// <summary> /// Конвертировать тип цвета печати в версию из приложения /// </summary> public static DepartmentType FromApplication(DepartmentTypeApp departmentTypeApp) => Enum.TryParse(departmentTypeApp.ToString(), true, out DepartmentType departmentType) ? departmentType : throw new FormatException(nameof(departmentTypeApp));
/// <summary> /// Проверка фамилии и отдела /// </summary> public bool SurnameAndDepartmentEqual(string surname, DepartmentTypeApp departmentType) => SurnameEqual(surname) && DepartmentType == departmentType;
/// <summary> /// Конвертировать тип отдела в версию из приложения /// </summary> public static DepartmentType FromApplication(this DepartmentTypeApp departmentTypeApp) => DepartmentToApplicationConverter.FromApplication(departmentTypeApp);