fix/fix

Co-authored-by: MaxchilKH <m.w.bohdanowicz@gmail.com>
This commit is contained in:
maxchil 2020-11-12 01:15:55 +01:00
parent 6d1103a6b9
commit 9939f36900
3 changed files with 25 additions and 3 deletions

View File

@ -30,7 +30,7 @@ namespace InternshipSystem.Api.UseCases
subjectRegistration = internshipRegistration;
}
public async Task<(DocumentState State, IEnumerable<string>)> UpdateInternshipRegistration(
public async Task<(DocumentState State, IEnumerable<ErrorDescription>)> UpdateInternshipRegistration(
UpdateRegistrationForm registrationCommand,
CancellationToken cancellationToken)
{

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using InternshipSystem.Core.Entity.Internship;
namespace InternshipSystem.Core
{
static internal class Extensions
{
public static IEnumerable<ErrorDescription> ToErrorDescription(this ValidationResult result)
{
return result.Errors.Select(failure => new ErrorDescription { Key = failure.ErrorCode, Parameters = failure.FormattedMessagePlaceholderValues });
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentValidation;
using FluentValidation.Results;
using InternshipSystem.Core.UglyOrmArtifacts;
namespace InternshipSystem.Core.Entity.Internship
@ -27,7 +28,7 @@ namespace InternshipSystem.Core.Entity.Internship
}
public (DocumentState State, IEnumerable<string>) ValidateStatus(Edition edition)
public (DocumentState State, IEnumerable<ErrorDescription>) ValidateStatus(Edition edition)
{
var validator = new Validator(edition);
@ -35,7 +36,7 @@ namespace InternshipSystem.Core.Entity.Internship
State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft;
return (State, result.Errors.Select(failure => failure.ToString()));
return (State, result.ToErrorDescription());
}
public class Validator : AbstractValidator<InternshipRegistration>
@ -75,4 +76,10 @@ namespace InternshipSystem.Core.Entity.Internship
}
}
}
public class ErrorDescription
{
public string Key { get; set; }
public Dictionary<string, object> Parameters { get; set; }
}
}