diff --git a/server/StrDss.Common/Constants.cs b/server/StrDss.Common/Constants.cs index eda4cc3e..d580c3bb 100644 --- a/server/StrDss.Common/Constants.cs +++ b/server/StrDss.Common/Constants.cs @@ -116,6 +116,7 @@ public static class PlatformFields public const string PrimaryTakedownRequestContactEmail = "PrimaryTakedownRequestContactEmail"; public const string SecondaryNoticeOfTakedownContactEmail = "SecondaryNoticeOfTakedownContactEmail"; public const string SecondaryTakedownRequestContactEmail = "SecondaryTakedownRequestContactEmail"; + public const string PlatformType = "PlatformType"; } public static class RentalListingExport @@ -235,6 +236,7 @@ public static class FieldTypes public static class CodeSet { public const string LicenceStatus = "Licence Status"; + public const string PlatformTypes = "Platform Types"; } public static class StrDssIdProviders diff --git a/server/StrDss.Data/Repositories/CodeSetRepository.cs b/server/StrDss.Data/Repositories/CodeSetRepository.cs index a2b26955..b5a54c4d 100644 --- a/server/StrDss.Data/Repositories/CodeSetRepository.cs +++ b/server/StrDss.Data/Repositories/CodeSetRepository.cs @@ -34,6 +34,17 @@ public async Task> LoadCodeSetAsync() }).ToListAsync() ); + commonCodes.AddRange(await + _dbContext.DssPlatformTypes + .AsNoTracking() + .Select(x => new CommonCodeDto + { + CodeSet = CodeSet.PlatformTypes, + CodeName = x.PlatformTypeNm, + CodeValue = x.PlatformType + }).ToListAsync() + ); + return commonCodes; } } diff --git a/server/StrDss.Service/OrganizationService.cs b/server/StrDss.Service/OrganizationService.cs index d4f96664..a797d12e 100644 --- a/server/StrDss.Service/OrganizationService.cs +++ b/server/StrDss.Service/OrganizationService.cs @@ -30,12 +30,14 @@ public interface IOrganizationService public class OrganizationService : ServiceBase, IOrganizationService { private IOrganizationRepository _orgRepo; + private ICodeSetRepository _codeSetRepo; public OrganizationService(ICurrentUser currentUser, IFieldValidatorService validator, IUnitOfWork unitOfWork, IMapper mapper, IHttpContextAccessor httpContextAccessor, ILogger logger, - IOrganizationRepository orgRepo) + IOrganizationRepository orgRepo, ICodeSetRepository codeSetRep) : base(currentUser, validator, unitOfWork, mapper, httpContextAccessor, logger) { _orgRepo = orgRepo; + _codeSetRepo = codeSetRep; } public async Task> GetOrganizationTypesAsnc() @@ -99,6 +101,11 @@ public async Task> GetPlatforms(int pageSize, int page private async Task>> ValidatePlatformCreateDto(IPlatformCreateDto dto, Dictionary> errors) where T : class, IPlatformCreateDto { + if (!_validator.CommonCodes.Any()) + { + _validator.CommonCodes = await _codeSetRepo.LoadCodeSetAsync(); + } + _validator.Validate(Entities.Platform, (T)dto, errors); if (errors.Any()) @@ -143,6 +150,11 @@ private async Task>> ValidatePlatformUpdateDto r MaxLength = 320, RegexInfo = RegexDefs.GetRegexInfo(RegexDefs.Email) }); + + rules.Add(new FieldValidationRule + { + EntityName = Entities.Platform, + FieldName = PlatformFields.PlatformType, + FieldType = FieldTypes.String, + Required = true, + CodeSet = CodeSet.PlatformTypes, + }); } }