public int GetHashCode(MessageRecipient obj) { unchecked { return ((obj.OrganizationBoxId != null ? obj.OrganizationBoxId.GetHashCode() : 0)*397) ^ (obj.DepartmentId != null ? obj.DepartmentId.GetHashCode() : 0); } }
/// <summary> /// Определяет является ли объект-параметр одинаковым с данным объектом /// </summary> /// <param name="p"></param> /// <returns></returns> protected bool Equals(MessageRecipient p) { return string.Equals(OrganizationBoxId, p.OrganizationBoxId) && string.Equals(DepartmentId, p.DepartmentId); }
/// <summary> /// Выбрать контрагента (например получателя) из списка доступных для обмена или /// указать вручную - например: указав ящик конктагента /// </summary> /// <returns></returns> private MessageRecipient ChooseExternalRecipient(List<string> selectedContactList) { var fromList = new UserInput.Option("1", "Из списка контрагентов", true, true); var manuallyEntry = new UserInput.Option("2", "Ввести вручную", false, true); var chooseOption = UserInput.ChooseOption("Выбрать получателя", new[] { fromList, manuallyEntry }); string organizationId; string boxAddress; if (chooseOption == fromList) { ContactSearchResult contactSearchResult; var contactList = new List<ContactSearchItem>(); var from = 0; const int pageSize = 20; do { contactSearchResult = _context.ServiceClient.SearchContacts( new ContactSearchOptions { OrganizationId = _context.CurrentOrganizationId, ContactStatus = ContactStatus.Active, From = from, Max = pageSize }); contactList.AddRange(contactSearchResult.Items); contactList.RemoveAll(c => selectedContactList.Any(value => value.Equals(c.BoxAddress))); from += pageSize; } while (contactSearchResult.TotalCount > from); var contragentOption = UserInput.ChooseOption ("Выберите получателя", contactList.Select( (c, i) => new UserInput.Option((i + 1).ToString(CultureInfo.InvariantCulture), c.ContragentName, i == 0, c))); var contactSearchItem = ((ContactSearchItem)contragentOption.Data); organizationId = contactSearchItem.ContragentId.ToString(CultureInfo.InvariantCulture); boxAddress = contactSearchItem.BoxAddress; } else { var address = UserInput.ReadParameter("Введите адрес получателя"); if (selectedContactList.Any(value => value.Equals(address))) { UserInput.Error("Получатель с таким адресом уже указан"); return null; } if (address.Equals(_context.CurrentBox)) { UserInput.Error("Отправитель не может быть указан в качестве получателя"); return null; } var organization = _context.ServiceClient.GetOrganizationBy(_context.CurrentBox, OrganizationByCriteria.ByBoxAddress, new OrganizationByCriteriaValues { BoxAddress = address }); if (organization == null) { UserInput.Error("Неправильно указан адресат"); return null; } UserInput.Success(string.Format("Выбрана организация: {0}", organization.Name)); organizationId = organization.OrganizationId; boxAddress = organization.BoxAddress; } var messageRecipient = new MessageRecipient { OrganizationBoxId = boxAddress }; if (UserInput.ChooseYesNo("Указать подразделение")) { var selectedDepartment = ChooseOrganizationStructureElement(organizationId); if (selectedDepartment != null) messageRecipient.DepartmentId = selectedDepartment.Id; } return messageRecipient; }
public MessageRecipientWithStatus(MessageRecipient recipient) { OrganizationBoxId = recipient.OrganizationBoxId; DepartmentId = recipient.DepartmentId; }
private MessageRecipient ChooseExternalRecipient() { var fromList = new UserInput.Option("1", "Из списка контрагентов", true, true); var manuallyEntry = new UserInput.Option("2", "Ввести вручную", false, true); var chooseOption = UserInput.ChooseOption("Выбрать получателя", new[] { fromList, manuallyEntry, }); var organizationId = (string)null; var boxAddress = (string)null; if (chooseOption == fromList) { var contactSearchResult = context.ServiceClient.SearchContacts( new ContactSearchOptions { OrganizationId = context.CurrentOrganizationId, ContactStatus = ContactStatus.Active, From = 0, Max = 20 }); var contragentOption = UserInput.ChooseOption ("Выберите получателя", contactSearchResult.Items .Select((c, i) => new UserInput.Option((i + 1).ToString(), c.ContragentName, i == 0, c))); var contactSearchItem = ((ContactSearchItem)contragentOption.Data); organizationId = contactSearchItem.ContragentId.ToString(); boxAddress = contactSearchItem.BoxAddress; } else { var address = UserInput.ReadParameter("Введите адрес получателя"); var organization = context.ServiceClient.GetOrganizationBy(context.CurrentBox, OrganizationByCriteria.ByBoxAddress, new OrganizationByCriteriaValues { BoxAddress = address }); if (organization == null) { UserInput.Error("Неправильно указан адресат"); return null; } UserInput.Success(String.Format("Выбрана организация: {0}",organization.Name)); organizationId = organization.OrganizationId; boxAddress = organization.BoxAddress; } var messageRecipient = new MessageRecipient { OrganizationBoxId = boxAddress }; if (UserInput.ChooseYesNo("Указать подразделение")) { var selectedDepartment = ChooseOrganizationStructureElement(organizationId); if (selectedDepartment != null) messageRecipient.DepartmentId = selectedDepartment.Id; } return messageRecipient; }