diff --git a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs index bf98daa5..8eaddbe1 100644 --- a/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs +++ b/AsbCloudInfrastructure/Repository/WitsRecordRepository.cs @@ -1,5 +1,4 @@ using AsbCloudApp.Services; -using AsbCloudDb; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; @@ -54,9 +53,7 @@ namespace AsbCloudInfrastructure.Repository .Where(d => d.DateTime <= end) .AsNoTracking(); var data = await query.ToListAsync(token); - return data - .Where(d => d is not null) - .Select(d => Convert(d, timezoneHours)); + return data.Select(d => Convert(d, timezoneHours)); } public async Task> GetLastAsync(int idTelemetry, CancellationToken token) diff --git a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs index 816cd836..78f15615 100644 --- a/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs +++ b/AsbCloudInfrastructure/Services/DrillingProgram/DrillingProgramService.cs @@ -369,10 +369,13 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram { var file = await fileService.GetOrDefaultAsync(fileMark.IdFile, token); var well = await wellService.GetOrDefaultAsync(file!.IdWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(file.IdWell)); + var user = file.Author!; var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, "Загруженный вами документ полностью согласован"); - var body = factory.MakeMailBodyForPublisherOnFullAccept(well, user.Name, file.Id, file.Name); + var body = factory.MakeMailBodyForPublisherOnFullAccept(well, user.Name ?? string.Empty, file.Id, file.Name); emailService.EnqueueSend(user.Email, subject, body); } @@ -381,10 +384,13 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram { var file = await fileService.GetOrDefaultAsync(fileMark.IdFile, token); var well = await wellService.GetOrDefaultAsync(file!.IdWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(file.IdWell)); + var user = file.Author!; var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, "Загруженный вами документ отклонен"); - var body = factory.MakeMailBodyForPublisherOnReject(well, user.Name, file.Id, file.Name, fileMark); + var body = factory.MakeMailBodyForPublisherOnReject(well, user.Name ?? string.Empty, file.Id, file.Name, fileMark); emailService.EnqueueSend(user.Email, subject, body); } @@ -392,6 +398,9 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram private async Task NotifyApproversAsync(DrillingProgramPart part, int idFile, string fileName, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(part.IdWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(part.IdWell)); + var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, "Загружен новый документ для согласования."); var users = part.RelatedUsers @@ -400,7 +409,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram foreach (var user in users) { - var body = factory.MakeMailBodyForApproverNewFile(well, user.Name, idFile, fileName); + var body = factory.MakeMailBodyForApproverNewFile(well, user.Name ?? string.Empty, idFile, fileName); emailService.EnqueueSend(user.Email, subject, body); } } @@ -408,9 +417,12 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram private async Task NotifyNewPublisherAsync(int idWell, UserDto user, string documentCategory, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(idWell, token); + if (well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + var factory = new DrillingMailBodyFactory(configuration); var subject = factory.MakeSubject(well, $"От вас ожидается загрузка на портал документа «{documentCategory}»"); - var body = factory.MakeMailBodyForNewPublisher(well, user.Name, documentCategory); + var body = factory.MakeMailBodyForNewPublisher(well, user.Name ?? string.Empty, documentCategory); emailService.EnqueueSend(user.Email, subject, body); } diff --git a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs index 91121ef6..e683532a 100644 --- a/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs +++ b/AsbCloudInfrastructure/Services/WellFinalDocumentsService.cs @@ -125,18 +125,30 @@ namespace AsbCloudInfrastructure.Services { var category = await fileCategoryService.GetOrDefaultAsync(item.IdCategory, token); var well = await wellService.GetOrDefaultAsync(item.IdWell, token); + if(well is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(item.IdWell)); - SendMessage(well, user, category.Name, message); + SendMessage(well, user, category?.Name ?? string.Empty, message); } } } - private void SendMessage(WellDto? well, UserDto user, string documentCategory, string message) + private void SendMessage(WellDto well, UserDto user, string documentCategory, string message) { var factory = new WellFinalDocumentMailBodyFactory(configuration); var subject = factory.MakeSubject(well, documentCategory); - var body = factory.MakeMailBodyForWellFinalDocument(well, user.Name ?? user.Surname, string.Format(message, documentCategory)); - emailService.EnqueueSend(user.Email, subject, body); + + if(!string.IsNullOrEmpty(user.Email)) + { + var body = factory.MakeMailBodyForWellFinalDocument( + well, + (user.Name ?? user.Surname ?? string.Empty), + string.Format(message, documentCategory) + ); + + emailService.EnqueueSend(user.Email, subject, body); + } + } } #nullable disable diff --git a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs index 703d815f..028b16e0 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs @@ -82,7 +82,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService var tvdList = tvd.ToList(); var facts = tvd .Where(t => t.Fact is not null) - .Select(t => t.Fact) + .Select(t => t.Fact!) .ToList(); DateTime lastFactDate = default;