diff --git a/AsbCloudApp/Data/WellOperationDto.cs b/AsbCloudApp/Data/WellOperationDto.cs index f2a2d65f..e21471ce 100644 --- a/AsbCloudApp/Data/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperationDto.cs @@ -1,5 +1,5 @@ -using AsbCloudApp.Validation; -using System; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace AsbCloudApp.Data @@ -7,7 +7,7 @@ namespace AsbCloudApp.Data /// /// Операции на скважине (заведенные пользователем) /// - public class WellOperationDto : ItemInfoDto, IId, IWellRelated + public class WellOperationDto : ItemInfoDto, IId, IWellRelated, IValidatableObject { /// public int Id { get; set; } @@ -86,8 +86,8 @@ namespace AsbCloudApp.Data /// /// Дата начала операции /// - [DateValidation(GtDate = "2010-01-01T00:00:00")] - public DateTime DateStart { get; set; } + + public DateTimeOffset DateStart { get; set; } /// /// Продолжительность, часы @@ -100,5 +100,24 @@ namespace AsbCloudApp.Data /// [StringLength(4096, ErrorMessage = "Комментарий не может быть длиннее 4096 символов")] public string? Comment { get; set; } + + /// + /// Валидация даты + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + if (!(DateStart is DateTimeOffset dateTimeOffset)) + yield return new ValidationResult( + $"{nameof(DateStart)}: дата DateStart указана не в формате DateTimeOffset", + new[] { nameof(DateStart) }); + + var gtDate = new DateTimeOffset(2010, 1, 1, 0, 0, 0, TimeSpan.Zero); + if (DateStart <= gtDate) + yield return new ValidationResult( + $"{nameof(DateStart)}: DateStart не может быть меньше {gtDate}", + new[] { nameof(DateStart) }); + } } } diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index fbc94e02..fb0a8c12 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -347,7 +347,7 @@ public class WellOperationRepository : IWellOperationRepository { var entity = dto.Adapt(); entity.Id = default; - entity.DateStart = dto.DateStart.ToUtcDateTimeOffset(timezone.Hours); + entity.DateStart = dto.DateStart.ToUniversalTime(); entity.IdWell = idWell; db.WellOperations.Add(entity); } @@ -365,7 +365,7 @@ public class WellOperationRepository : IWellOperationRepository { var timezone = wellService.GetTimezone(dto.IdWell); var entity = dto.Adapt(); - entity.DateStart = dto.DateStart.ToUtcDateTimeOffset(timezone.Hours); + entity.DateStart = dto.DateStart.ToUniversalTime(); db.WellOperations.Update(entity); var result = await db.SaveChangesAsync(token); @@ -449,7 +449,6 @@ public class WellOperationRepository : IWellOperationRepository CategoryName = o.OperationCategory.Name, WellSectionTypeName = o.WellSectionType.Caption, - DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), DepthStart = o.DepthStart, DepthEnd = o.DepthEnd, diff --git a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs index d46bfff1..f1c44ec3 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/ScheduleReportService.cs @@ -140,7 +140,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService .Select(t => t.Fact!) .ToList(); - DateTime lastFactDate = default; + DateTimeOffset lastFactDate = default; var lastFactI = 0; int i = 0; @@ -290,7 +290,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService static DateTime GetEndDate(WellOperationDto operation) => operation is not null - ? operation.DateStart.AddHours(operation.DurationHours) + ? operation.DateStart.Date.AddHours(operation.DurationHours) : default; var endDatePlan = planLast is not null ? GetEndDate(planLast) : default; diff --git a/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs b/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs index b75b6947..d635d53d 100644 --- a/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs +++ b/AsbCloudWebApi.Tests/UnitTests/Services/DailyReportServiceTest.cs @@ -238,8 +238,8 @@ public class DailyReportServiceTest fakeDatesRange = new DatesRangeDto { - From = fakeFirstFactWellOperation.DateStart, - To = fakeLastFactWellOperation.DateStart + From = fakeFirstFactWellOperation.DateStart.Date, + To = fakeLastFactWellOperation.DateStart.Date }; dailyReportService = new DailyReportService(wellServiceMock,