67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using FluentValidation;
|
|
using FluentValidation.Results;
|
|
using InternshipSystem.Core.Entity.Internship;
|
|
using InternshipSystem.Core.UglyOrmArtifacts;
|
|
|
|
namespace InternshipSystem.Core
|
|
{
|
|
public class InternshipRegistration
|
|
{
|
|
public long Id { get; set; }
|
|
public Company Company { get; set; }
|
|
public BranchOffice BranchAddress { get; set; }
|
|
public DateTime Start { get; set; }
|
|
public DateTime End { get; set; }
|
|
public Mentor Mentor { get; set; }
|
|
public List<ProgramSubject> Subjects { get; set; }
|
|
public InternshipType Type { get; set; }
|
|
public DocumentState State { get; set; }
|
|
|
|
public static InternshipRegistration Create()
|
|
{
|
|
return new InternshipRegistration();
|
|
}
|
|
|
|
|
|
public string ValidateStatus(Edition edition)
|
|
{
|
|
var validator = new Validator(edition);
|
|
|
|
var result = validator.Validate(this);
|
|
|
|
State = result.IsValid ? DocumentState.Submitted : DocumentState.Draft;
|
|
|
|
return result.ToString();
|
|
}
|
|
|
|
public class Validator : AbstractValidator<InternshipRegistration>
|
|
{
|
|
public Validator(Edition edition)
|
|
{
|
|
RuleFor(x => x.Company)
|
|
.SetValidator(new Company.Validator())
|
|
.NotNull();
|
|
RuleFor(x => x.BranchAddress)
|
|
.SetValidator(new BranchOffice.Validator())
|
|
.NotNull();
|
|
RuleFor(x => x.Mentor)
|
|
.SetValidator(new Mentor.Validate())
|
|
.NotNull();
|
|
RuleFor(x => x.Subjects)
|
|
.NotEmpty();
|
|
RuleFor(x => x.Type)
|
|
.NotNull();
|
|
RuleFor(x => x.Start)
|
|
.GreaterThanOrEqualTo(edition.EditionStart)
|
|
.LessThan(x => x.End)
|
|
.NotEmpty();
|
|
RuleFor(x => x.End)
|
|
.LessThanOrEqualTo(edition.EditionFinish)
|
|
.GreaterThan(x => x.Start)
|
|
.NotEmpty();
|
|
}
|
|
}
|
|
}
|
|
} |