Фикс бага: на свойство DateStart модели WellOperationDto навешан атрибут, проверяющий дату + сохранение пользователя, импортирующего данные о фактиечских операциях

This commit is contained in:
Olga Nemt 2023-05-22 14:46:19 +05:00
parent 246056d3a4
commit 2e96f1982f
4 changed files with 11 additions and 4 deletions

View File

@ -1,4 +1,5 @@
using System;
using AsbCloudApp.ValidationAttributes;
using System;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data
@ -87,6 +88,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// Дата начала операции
/// </summary>
[DateValidation(AllowNull = false)]
public DateTime DateStart { get; set; }
/// <summary>

View File

@ -25,7 +25,8 @@ namespace AsbCloudApp.Services
/// </summary>
/// <param name="idWell"></param>
/// <param name="stream"></param>
/// <param name="idUser"></param>
/// <param name="deleteWellOperationsBeforeImport">Очистить старые перед импортом (если файл проходит валидацию)</param>
void Import(int idWell, Stream stream, bool deleteWellOperationsBeforeImport = false);
void Import(int idWell, Stream stream, int idUser, bool deleteWellOperationsBeforeImport = false);
}
}

View File

@ -73,12 +73,15 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
this.wellService = wellService;
}
public void Import(int idWell, Stream stream, bool deleteWellOperationsBeforeImport = false)
public void Import(int idWell, Stream stream, int idUser, bool deleteWellOperationsBeforeImport = false)
{
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
var operations = ParseFileStream(stream);
foreach (var operation in operations)
{
operation.IdWell = idWell;
operation.IdUser = idUser;
}
SaveOperations(idWell, operations, deleteWellOperationsBeforeImport);
}
@ -177,6 +180,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var entity = o.Adapt<WellOperation>();
entity.IdWell = idWell;
entity.DateStart = o.DateStart.ToUtcDateTimeOffset(timezone.Hours);
entity.LastUpdateDate = DateTimeOffset.UtcNow;
return entity;
});
db.WellOperations.AddRange(entities);

View File

@ -308,7 +308,7 @@ namespace AsbCloudWebApi.Controllers
try
{
wellOperationImportService.Import(idWell, stream, (options & 1) > 0);
wellOperationImportService.Import(idWell, stream, idUser!.Value, (options & 1) > 0);
}
catch (FileFormatException ex)
{