示例#1
0
 public ChangeHistoryController(IChangeHistoryService svc, ICachedLookupService lookupService, IEstablishmentReadService establishmentReadService, IGroupReadService groupReadService, IGroupDownloadService groupDownloadService)
 {
     _svc                      = svc;
     _lookupService            = lookupService;
     _establishmentReadService = establishmentReadService;
     _groupReadService         = groupReadService;
     _groupDownloadService     = groupDownloadService;
 }
 public GroupSearchController(
     IGroupReadService groupReadService,
     IGroupDownloadService groupDownloadService,
     ICachedLookupService lookupService)
 {
     _groupReadService     = groupReadService;
     _lookupService        = lookupService;
     _groupDownloadService = groupDownloadService;
 }
示例#3
0
 public GovernanceDelegationController(
     IGroupReadService groupReadService,
     IGroupsWriteService groupWriteService,
     LayoutHelper layoutHelper)
 {
     _groupReadService  = groupReadService;
     _groupWriteService = groupWriteService;
     _layoutHelper      = layoutHelper;
 }
 public GroupCorporateContactController(
     IGroupReadService groupReadService,
     IGroupsWriteService groupWriteService,
     LayoutHelper layoutHelper)
 {
     _groupReadService  = groupReadService;
     _groupWriteService = groupWriteService;
     _layoutHelper      = layoutHelper;
 }
 public SearchController(IEstablishmentReadService establishmentReadService,
                         ICachedLookupService cachedLookupService,
                         IGroupReadService groupReadService,
                         IPlacesLookupService placesService)
 {
     _placesService            = placesService;
     _cachedLookupService      = cachedLookupService;
     _establishmentReadService = establishmentReadService;
     _groupReadService         = groupReadService;
 }
 public SitemapController(IEstablishmentReadService establishmentReadService,
                          IGroupReadService groupReadService,
                          ICacheAccessor cacheAccessor,
                          ICachedLookupService lookupService)
 {
     _establishmentReadService = establishmentReadService;
     _groupReadService         = groupReadService;
     _cacheAccessor            = cacheAccessor;
     _lookupService            = lookupService;
 }
示例#7
0
 public LayoutHelper(
     NomenclatureService nomenclatureService,
     IGroupReadService groupReadService,
     IEstablishmentReadService establishmentReadService,
     ICachedLookupService cls)
 {
     _nomenclatureService      = nomenclatureService;
     _establishmentReadService = establishmentReadService;
     _groupReadService         = groupReadService;
     _cls = cls;
 }
示例#8
0
 public GovernorSearchController(IGovernorDownloadService governorDownloadService,
                                 IGovernorsReadService governorsReadService,
                                 ICachedLookupService cachedLookupService,
                                 IGroupReadService groupReadService,
                                 IEstablishmentReadService establishmentReadService)
 {
     _governorDownloadService  = governorDownloadService;
     _governorsReadService     = governorsReadService;
     _cachedLookupService      = cachedLookupService;
     _establishmentReadService = establishmentReadService;
     _groupReadService         = groupReadService;
 }
示例#9
0
 public GovernorController(
     IGovernorsReadService governorsReadService,
     NomenclatureService nomenclatureService,
     ICachedLookupService cachedLookupService,
     IGovernorsWriteService governorsWriteService,
     IGroupReadService groupReadService,
     IEstablishmentReadService establishmentReadService,
     ILayoutHelper layoutHelper)
 {
     _governorsReadService     = governorsReadService;
     _nomenclatureService      = nomenclatureService;
     _cachedLookupService      = cachedLookupService;
     _governorsWriteService    = governorsWriteService;
     _groupReadService         = groupReadService;
     _establishmentReadService = establishmentReadService;
     _layoutHelper             = layoutHelper;
 }
示例#10
0
 public GroupController(
     ICachedLookupService cachedLookupService,
     ISecurityService securityService,
     IGroupReadService groupReadService,
     IEstablishmentReadService establishmentReadService,
     IGroupsWriteService groupWriteService,
     ICompaniesHouseService companiesHouseService,
     NomenclatureService nomenclatureService)
 {
     _lookup                   = cachedLookupService;
     _securityService          = securityService;
     _groupReadService         = groupReadService;
     _establishmentReadService = establishmentReadService;
     _groupWriteService        = groupWriteService;
     _companiesHouseService    = companiesHouseService;
     _nomenclatureService      = nomenclatureService;
 }
示例#11
0
        public ValidateChildrensCentreStep2Validator(IGroupReadService groupReadService, ISecurityService securityService)
        {
            RuleFor(x => x.LocalAuthorityId)
            .NotNull()
            .WithMessage("This field is mandatory")
            .WithSummaryMessage("Please select a local authority for the group");

            RuleFor(x => x.OpenDate)
            .Must(x => !x.IsEmpty())
            .WithMessage("Open date missing. Please enter the date")
            .Must(x => x.IsValid() || x.IsEmpty())
            .WithMessage("Open date is invalid. Please enter a valid date");

            RuleFor(x => x.GroupName)
            .NotEmpty()
            .WithMessage("Enter an Group name")

            .MustAsync(async(model, name, ct) => !(await groupReadService.ExistsAsync(securityService.CreateAnonymousPrincipal(), name: name, localAuthorityId: model.LocalAuthorityId.Value)))
            .WithMessage("Group name already exists at this authority, please select another name");

            //.MustAsync(async (model, name, ct) => !(await groupReadService.ExistsAsync(securityService.CreateAnonymousPrincipal(), name: name)))
            //.WithMessage("Group name already exists, please select another name");
        }
        public GroupEditorViewModelValidator(IGroupReadService groupReadService, IEstablishmentReadService establishmentReadService, IPrincipal principal, ISecurityService securityService)
        {
            _groupReadService         = groupReadService;
            _establishmentReadService = establishmentReadService;


            CascadeMode = CascadeMode.StopOnFirstFailure;

            // Searching for an establishment to link....
            When(x => x.Action == ActionLinkedEstablishmentSearch, () =>
            {
                RuleFor(x => x.LinkedEstablishments.LinkedEstablishmentSearch.Urn)
                .Cascade(CascadeMode.StopOnFirstFailure)

                .Must(x => x.IsInteger())
                .WithMessage("Please enter a valid URN")
                .WithSummaryMessage("The supplied URN is not valid")

                .Must((model, x) => !model.LinkedEstablishments.Establishments.Select(e => e.Urn).Contains(x.ToInteger().Value))
                .WithMessage("This establishment is already in this group. Please enter a different URN")
                .WithSummaryMessage("This establishment is already in this group. Please enter a different URN")

                .MustAsync(async(x, ct) =>
                {
                    return((await _establishmentReadService.GetAsync(x.ToInteger().Value, principal).ConfigureAwait(false)).ReturnValue != null);
                }).WithMessage("The establishment was not found").WithSummaryMessage("The establishment was not found");
            });

            // Having found an establishment to link, validate the joined date if supplied...
            When(x => x.Action == ActionLinkedEstablishmentAdd, () =>
            {
                RuleFor(x => x.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate)
                .Must(x => x.IsValid())
                .WithMessage("This is not a valid date")
                .WithSummaryMessage("The Joined Date specified is not valid")

                .Must((model, joinDate) => VerifyJoinedDate(joinDate.ToDateTime(), model))
                .WithMessage(x => $"The join date you entered is before the {x.GroupType}'s open date of {x.OpenDate}. Please enter a later date.");
            });

            // Having edited a joined date, validate the date...
            When(x => x.Action == ActionLinkedEstablishmentSave, () =>
            {
                RuleFor(x => x.LinkedEstablishments.Establishments.Single(e => e.EditMode).JoinedDateEditable).Must(x => x.IsValid())
                .WithMessage("This is not a valid date")
                .WithSummaryMessage("The Joined Date specified is not valid")

                .Must((model, joinDate) => VerifyJoinedDate(joinDate.ToDateTime(), model))
                .WithMessage(x => $"The join date you entered is before the {x.GroupType}'s open date of {x.OpenDate}. Please enter a later date.");
            });

            // On getting to the save page....
            When(x => x.Action == ActionSave || x.Action == ActionDetails, () =>
            {
                When(m => m.GroupTypeMode == eGroupTypeMode.ChildrensCentre, () =>
                {
                    RuleFor(x => x.LocalAuthorityId).NotNull()
                    .WithMessage("This field is mandatory")
                    .WithSummaryMessage("Please select a local authority for the group")
                    .When(x => x.SaveGroupDetail);
                });

                RuleFor(x => x.GroupTypeId).NotNull().WithMessage("Group Type must be supplied");

                RuleFor(x => x.OpenDate)
                .Must(x => !x.IsEmpty())
                .WithMessage(x => $"{x.OpenDateLabel} missing. Please enter the date")
                .When(x => !x.GroupUId.HasValue, ApplyConditionTo.CurrentValidator)
                .Must(x => x.IsValid() || x.IsEmpty())
                .WithMessage(x => $"{x.OpenDateLabel} is invalid. Please enter a valid date");

                When(x => x.CanUserEditClosedDate &&
                     x.GroupType == eLookupGroupType.MultiacademyTrust &&
                     x.OriginalStatusId != (int)eLookupGroupStatus.Closed &&
                     x.StatusId == (int)eLookupGroupStatus.Closed &&
                     x.SaveGroupDetail, () =>
                {
                    RuleFor(x => x.ClosedDate)
                    .Must(x => !x.IsEmpty())
                    .WithMessage("Please enter a date for the closure of this multi-academy trust")
                    .Must(x => x.IsValid() || x.IsEmpty())
                    .WithMessage("Closed date is invalid. Please enter a valid date.");
                });

                RuleFor(x => x.GroupName)
                .Cascade(CascadeMode.StopOnFirstFailure)
                .NotEmpty()
                .WithMessage(x => $"Please enter the {x.FieldNamePrefix.ToLower()} name")
                .When(x => x.SaveGroupDetail);

                RuleFor(x => x.GroupId)
                .Cascade(CascadeMode.StopOnFirstFailure)
                .NotEmpty()
                .WithMessage("Please enter a Group ID")
                .WithSummaryMessage("Please enter a Group ID")
                .MustAsync(async(model, groupId, ct) => !(await _groupReadService.ExistsAsync(securityService.CreateAnonymousPrincipal(), groupId: groupId, existingGroupUId: model.GroupUId)))
                .WithMessage("Group ID already exists. Enter a different group ID.")
                .When(x => x.GroupTypeMode.OneOfThese(eGroupTypeMode.AcademyTrust, eGroupTypeMode.Sponsor) && x.SaveGroupDetail, ApplyConditionTo.AllValidators);

                When(x => x.OpenDate.ToDateTime().HasValue, () =>
                {
                    RuleForEach(x => x.LinkedEstablishments.Establishments)
                    .Must((model, estab) => VerifyJoinedDate(estab.JoinedDateEditable.ToDateTime() ?? estab.JoinedDate, model))
                    .When(x => x.OpenDate.ToDateTime().GetValueOrDefault().Date == DateTime.Now.Date)
                    .WithMessage("The join date you entered is before today. Please enter a later date.")
                    .WithSummaryMessage("The join date you entered is before today. Please enter a later date.")

                    .Must((model, estab) => VerifyJoinedDate(estab.JoinedDateEditable.ToDateTime() ?? estab.JoinedDate, model))
                    .When(x => x.OpenDate.ToDateTime().GetValueOrDefault().Date != DateTime.Now.Date)
                    .WithMessage(x => $"The join date you entered is before the {x.GroupType}'s open date of {x.OpenDate}. Please enter a later date.");
                });
            });

            // Specific addition only triggered upon Saving ChildrensCentres through the creation tool
            When(x => x.Action == ActionSave && x.ActionName == eChildrensCentreActions.Step3, () =>
            {
                When(m => m.GroupTypeMode == eGroupTypeMode.ChildrensCentre, () =>
                {
                    RuleFor(x => x.LinkedEstablishments.Establishments)
                    .Must(x => x.Count >= 2)
                    .WithMessage("Add more centres to the group")
                    .WithSummaryMessage("You need to add at least two centres");
                });
            });
        }
示例#13
0
        public GroupEditorViewModelValidator(IGroupReadService groupReadService, IEstablishmentReadService establishmentReadService, IPrincipal principal, ISecurityService securityService)
        {
            _groupReadService         = groupReadService;
            _establishmentReadService = establishmentReadService;


            CascadeMode = CascadeMode.StopOnFirstFailure;

            // Searching for an establishment to link....
            When(x => x.Action == ActionLinkedEstablishmentSearch, () =>
            {
                RuleFor(x => x.LinkedEstablishments.LinkedEstablishmentSearch.Urn)
                .Cascade(CascadeMode.StopOnFirstFailure)

                .Must(x => x.IsInteger())
                .WithMessage("Please enter a valid URN")
                .WithSummaryMessage("The supplied URN is not valid")

                .Must((model, x) => !model.LinkedEstablishments.Establishments.Select(e => e.Urn).Contains(x.ToInteger().Value))
                .WithMessage("This establishment is already in this group. Please enter a different URN")
                .WithSummaryMessage("This establishment is already in this group. Please enter a different URN")

                .MustAsync(async(x, ct) =>
                {
                    return((await _establishmentReadService.GetAsync(x.ToInteger().Value, principal).ConfigureAwait(false)).ReturnValue != null);
                }).WithMessage("The establishment was not found").WithSummaryMessage("The establishment was not found");
            });

            // Having found an establishment to link, validate the joined date if supplied...
            When(x => x.Action == ActionLinkedEstablishmentAdd, () =>
            {
                RuleFor(x => x.LinkedEstablishments.LinkedEstablishmentSearch.JoinedDate)
                .Must(x => x.IsValid())
                .WithMessage("This is not a valid date")
                .WithSummaryMessage("The Joined Date specified is not valid")

                .Must((model, joinDate) => VerifyJoinedDate(joinDate.ToDateTime(), model))
                .WithMessage("The join date you entered is before the {0}'s open date of {1}. Please enter a later date.", m => m.GroupType, m => m.OpenDate);
            });

            // Having edited a joined date, validate the date...
            When(x => x.Action == ActionLinkedEstablishmentSave, () =>
            {
                RuleFor(x => x.LinkedEstablishments.Establishments.Single(e => e.EditMode).JoinedDateEditable).Must(x => x.IsValid())
                .WithMessage("This is not a valid date")
                .WithSummaryMessage("The Joined Date specified is not valid")

                .Must((model, joinDate) => VerifyJoinedDate(joinDate.ToDateTime(), model))
                .WithMessage("The join date you entered is before the {0}'s open date of {1}. Please enter a later date.", m => m.GroupType, m => m.OpenDate);
            });

            // On saving the group record....
            When(x => x.Action == ActionSave, () =>
            {
                When(m => m.GroupTypeMode == eGroupTypeMode.ChildrensCentre, () =>
                {
                    RuleFor(x => x.LocalAuthorityId).NotNull()
                    .WithMessage("This field is mandatory")
                    .WithSummaryMessage("Please select a local authority for the group")
                    .When(x => x.SaveGroupDetail);
                });

                RuleFor(x => x.GroupTypeId).NotNull().WithMessage("Group Type must be supplied");

                RuleFor(x => x.OpenDate)
                .Must(x => !x.IsEmpty())
                .WithMessage("{0} missing. Please enter the date", x => x.OpenDateLabel)
                .When(x => !x.GroupUId.HasValue, ApplyConditionTo.CurrentValidator)
                .Must(x => x.IsValid() || x.IsEmpty())
                .WithMessage("{0} is invalid. Please enter a valid date", x => x.OpenDateLabel);

                RuleFor(x => x.GroupName)
                .Cascade(CascadeMode.StopOnFirstFailure)
                .NotEmpty()
                .WithMessage("Please enter the {0} name", x => x.FieldNamePrefix.ToLower())
                .When(x => x.SaveGroupDetail);

                RuleFor(x => x.GroupId)
                .Cascade(CascadeMode.StopOnFirstFailure)
                .NotEmpty()
                .WithMessage("This field is mandatory")
                .WithSummaryMessage("Please enter a Group ID")
                .MustAsync(async(model, groupId, ct) => !(await _groupReadService.ExistsAsync(securityService.CreateAnonymousPrincipal(), groupId: groupId, existingGroupUId: model.GroupUId)))
                .WithMessage("Group ID already exists. Enter a different group ID.")
                .When(x => x.GroupTypeMode.OneOfThese(eGroupTypeMode.AcademyTrust, eGroupTypeMode.Sponsor) && x.SaveGroupDetail, ApplyConditionTo.AllValidators);

                RuleForEach(x => x.LinkedEstablishments.Establishments)
                .Must((model, estab) => VerifyJoinedDate(estab.JoinedDateEditable.ToDateTime() ?? estab.JoinedDate, model))
                .When(x => x.OpenDate.ToDateTime().Value.Date == DateTime.Now.Date)
                .WithMessage("The join date you entered is before today. Please enter a later date.")
                .WithSummaryMessage("The join date you entered is before today. Please enter a later date.")

                .Must((model, estab) => VerifyJoinedDate(estab.JoinedDateEditable.ToDateTime() ?? estab.JoinedDate, model))
                .When(x => x.OpenDate.ToDateTime().Value.Date != DateTime.Now.Date)
                .WithMessage("The join date you entered is before the {0}'s open date of {1}. Please enter a later date.", m => m.GroupType, m => m.OpenDate);
            });
        }