public async Task <Result> ValidateAsync(Organisation organisation)
        {
            if (organisation is null)
            {
                throw new ArgumentNullException(nameof(organisation));
            }

            var persistedOrganisation = await organisationRepository.GetByOdsCodeAsync(organisation.OdsCode);

            return(persistedOrganisation is null
                ? Result.Success()
                : Result.Failure(new List <ErrorDetails> {
                OrganisationErrors.OrganisationAlreadyExists()
            }));
        }
示例#2
0
        public async Task <ActionResult> GetByOdsCodeAsync(string odsCode)
        {
            if (string.IsNullOrWhiteSpace(odsCode))
            {
                return(NotFound());
            }

            var odsOrganisation = await odsRepository.GetBuyerOrganisationByOdsCodeAsync(odsCode);

            if (odsOrganisation is null)
            {
                return(NotFound());
            }

            if (!(odsOrganisation.IsActive && odsOrganisation.IsBuyerOrganisation))
            {
                return(new StatusCodeResult(StatusCodes.Status406NotAcceptable));
            }

            var addressModel = odsOrganisation.Address is null ? null : new AddressModel
            {
                Line1    = odsOrganisation.Address.Line1,
                Line2    = odsOrganisation.Address.Line2,
                Line3    = odsOrganisation.Address.Line3,
                Line4    = odsOrganisation.Address.Line4,
                Town     = odsOrganisation.Address.Town,
                County   = odsOrganisation.Address.County,
                Postcode = odsOrganisation.Address.Postcode,
                Country  = odsOrganisation.Address.Country,
            };

            var organisation = await organisationRepository.GetByOdsCodeAsync(odsCode);

            return(Ok(new OdsOrganisationModel
            {
                OdsCode = odsOrganisation.OdsCode,
                OrganisationId = organisation?.OrganisationId,
                OrganisationName = odsOrganisation.OrganisationName,
                PrimaryRoleId = odsOrganisation.PrimaryRoleId,
                Address = addressModel,
            }));
        }