WellContactService.GetAsync user mapping

This commit is contained in:
ngfrolov 2023-06-22 15:59:08 +05:00
parent 447478836b
commit 5d5fe21c91
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -22,7 +22,6 @@ namespace AsbCloudInfrastructure.Services
public async Task<IEnumerable<CompanyWithUsersDto>> 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<CompanyDto>(),
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<CompanyDto>(),
Email = u.Email,
Phone = u.Phone,
Position = u.Position,
IsContact = u.RelationContactsWells.Any(rel => rel.IdWell == wellId)
};
}
}
}