ContactServerFunctions.cs
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Parties.Contact;
namespace Sungero.Parties.Server
{
partial class ContactFunctions
{
/// <summary>
/// Получить дубли контактов.
/// </summary>
/// <returns>Контакты, дублирующие текущего по ФИО.</returns>
[Remote(IsPure = true)]
public IQueryable<IContact> GetDuplicates()
{
return Contacts.GetAll()
.Where(contact =>
!Equals(_obj, contact) &&
Equals(contact.Name, _obj.Name) &&
Equals(contact.Company, _obj.Company) &&
contact.Status != Sungero.Parties.Contact.Status.Closed);
}
/// <summary>
/// Получить контактное лицо по имени.
/// </summary>
/// <param name="name">Имя контакта.</param>
/// <param name="counterparty">Контрагент, владелец контакта.</param>
/// <returns>Найденный контакт, если он только один, иначе - null.</returns>
[Public]
public static Parties.IContact GetContactByName(string name, ICounterparty counterparty)
{
var contacts = GetContactsByName(name, name, counterparty)
.Where(x => x.Status != Sungero.CoreEntities.DatabookEntry.Status.Closed);
return contacts.Count() == 1 ? contacts.FirstOrDefault() : null;
}
/// <summary>
/// Получить контактные лица по имени.
/// </summary>
/// <param name="name">Имя в формате "Фамилия И.О." или "Фамилия Имя Отчество".</param>
/// <param name="personShortName">Имя в формате "Фамилия И.О.".</param>
/// <param name="counterparty">Контрагент, владелец контакта.</param>
/// <returns>Коллекция контактных лиц.</returns>
[Public]
public static IQueryable<IContact> GetContactsByName(string name, string personShortName, ICounterparty counterparty)
{
var nonBreakingSpace = new string('\u00A0', 1);
var space = new string('\u0020', 1);
name = name.ToLower().Replace(nonBreakingSpace, space).Replace(". ", ".");
var contacts = Contacts.GetAll()
.Where(x => (x.Name.ToLower().Replace(nonBreakingSpace, space).Replace(". ", ".") == name) ||
(x.Person != null && string.Equals(x.Person.ShortName,
personShortName,
StringComparison.InvariantCultureIgnoreCase)));
if (counterparty != null)
return contacts.Where(c => c.Company.Equals(counterparty));
return contacts;
}
}
}