Exemplo n.º 1
0
        public async Task <Result <Guid?> > CreateAsync(CreateOrganisationRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var organisation = new Organisation
            {
                Name                     = request.OrganisationName,
                OdsCode                  = request.OdsCode,
                PrimaryRoleId            = request.PrimaryRoleId,
                LastUpdated              = DateTime.UtcNow,
                CatalogueAgreementSigned = request.CatalogueAgreementSigned,
                Address                  = request.Address,
                OrganisationId           = Guid.NewGuid(),
            };

            var validationResult = await organisationValidator.ValidateAsync(organisation);

            if (!validationResult.IsSuccess)
            {
                return(Result.Failure <Guid?>(validationResult.Errors));
            }

            await organisationRepository.CreateOrganisationAsync(organisation);

            return(Result.Success((Guid?)organisation.OrganisationId));
        }