From 5d5fe21c91b9d4a585fc2b255d6c0d33736d60d3 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 22 Jun 2023 15:59:08 +0500 Subject: [PATCH] WellContactService.GetAsync user mapping --- .../Services/WellContactService.cs | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellContactService.cs b/AsbCloudInfrastructure/Services/WellContactService.cs index f0de37c7..7b9f7b4b 100644 --- a/AsbCloudInfrastructure/Services/WellContactService.cs +++ b/AsbCloudInfrastructure/Services/WellContactService.cs @@ -22,7 +22,6 @@ namespace AsbCloudInfrastructure.Services public async Task> GetAsync(int wellId, int contactTypeId, CancellationToken token) { - var query = db.Companies .Where(c => c.IdCompanyType == contactTypeId) .Where(c => c.RelationCompaniesWells.Any(rc => rc.IdWell == wellId)) @@ -30,7 +29,18 @@ namespace AsbCloudInfrastructure.Services { Caption = c.Caption, Id = c.Id, - Users = c.Users.Select(user => Convert(user, wellId)) + Users = c.Users.Select(u => new UserContactDto() + { + Id = u.Id, + Name = u.Name, + Patronymic = u.Patronymic, + Surname = u.Surname, + Company = u.Company.Adapt(), + Email = u.Email, + Phone = u.Phone, + Position = u.Position, + IsContact = u.RelationContactsWells.Any(rel => rel.IdWell == wellId) + }) }); var entities = await query.AsNoTracking() @@ -75,21 +85,5 @@ namespace AsbCloudInfrastructure.Services return await db.SaveChangesAsync(token) .ConfigureAwait(false); } - - private static UserContactDto Convert(User u, int wellId) - { - return new UserContactDto() - { - Id = u.Id, - Name = u.Name, - Patronymic = u.Patronymic, - Surname = u.Surname, - Company = u.Company.Adapt(), - Email = u.Email, - Phone = u.Phone, - Position = u.Position, - IsContact = u.RelationContactsWells.Any(rel => rel.IdWell == wellId) - }; - } } }