SHA256
GuestDocument - Add edit mode.
Added Edit mode for GuestDocument in GuestDocument details page.
This commit is contained in:
1 parent
a1a55aa396
commit
491ecc4cd1
4 files changed
+175
-16
No files matched your search
@@ -76,9 +76,77 @@ public class GuestDocumentEntityService(
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Result> UpdateDocumentAsync(GuestDocumentDTO dto)
|
||||
public async Task<Result> UpdateDocumentAsync(GuestDocumentDTO dto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var valResult = dtoValidator.Validate(dto);
|
||||
if (!valResult.IsValid)
|
||||
{
|
||||
logger.LogWarning("GuestDocumentService - UpdateDocument: Dto validation failed. Fix the errors: {errorList}", valResult.Errors);
|
||||
return Result.Fail(ResultCode.FailedValidation);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var dbContext = contextFactory.CreateDbContext();
|
||||
//Get current entity from DB.
|
||||
GuestDocument? dbItem = await dbContext.FindAsync<GuestDocument>(dto.Id, dto.Version);
|
||||
|
||||
if (dbItem == null)
|
||||
{
|
||||
logger.LogWarning("GuestDocumentService - UpdateDocument: Error updating GuestDocument (ID: '{id}'): GuestDocument not found!", dto.FullKey);
|
||||
return Result.Fail(ResultCode.NotFound);
|
||||
}
|
||||
|
||||
//Dto must be valid, so null warings shouldn't matter.
|
||||
GuestAddress addressItem = new()
|
||||
{
|
||||
Address = dto.Address,
|
||||
AddressCity = dto.AddressCity,
|
||||
AddressProvince = dto.AddressProvince,
|
||||
AddressState = dto.AddressState,
|
||||
AddressCountry = dto.AddressCountry!,
|
||||
ZipCode = dto.ZipCode,
|
||||
};
|
||||
|
||||
DateTime updateTime = DateTime.UtcNow;
|
||||
GuestDocument updatedItem = new()
|
||||
{
|
||||
Id = dbItem.Id,
|
||||
Version = dbItem.Version,
|
||||
DocumentType = dbItem.DocumentType,
|
||||
DocumentNum = dbItem.DocumentNum,
|
||||
IssueDate = dto.IssueDate != null ? DateOnly.FromDateTime(dto.IssueDate!.Value) : null,
|
||||
SupportNum = dto.SupportNum,
|
||||
Nationality = dto.Nationality!,
|
||||
Name = dto.Name!,
|
||||
Surname = dto.Surname!,
|
||||
Surname2 = dto.Surname2,
|
||||
BirthDate = DateOnly.FromDateTime(dto.BirthDate!.Value),
|
||||
Gender = dto.Gender,
|
||||
PhoneNumber = dto.PhoneNumber,
|
||||
EmailAddress = dto.EmailAddress,
|
||||
AddressDetails = addressItem,
|
||||
CreateTime = dbItem.CreateTime,
|
||||
UpdateTime = updateTime,
|
||||
IsLastVersion = dbItem.IsLastVersion,
|
||||
};
|
||||
|
||||
dbContext.Entry(dbItem).CurrentValues.SetValues(updatedItem);
|
||||
var result = await dbContext.SaveChangesAsync();
|
||||
|
||||
if (result != 1)
|
||||
{
|
||||
logger.LogWarning("GuestDocumentService - UpdateDocument: Unexpected updated entity count: {count}", result);
|
||||
}
|
||||
|
||||
logger.LogInformation("GuestDocumentService - UpdateDocument: GuestDocument Updated OK {id}", dbItem.GetFullKey());
|
||||
return Result.Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "GuestDocumentService - UpdateDocument: Error updating GuestDocument: '{id}'", dto.FullKey);
|
||||
return Result.FailUnknownError();
|
||||
}
|
||||
}
|
||||
|
||||
public Task<Result> DeleteDocumentAsync(GuestDocumentDTO dto)
|
||||
|
||||
Reference in new issue
Block a user