示例#1
0
        public bool Update(string id, OrganisationDetails organisationIn)
        {
            var filter = Builders <Organisation> .Filter.Eq(o => o.Id, id);

            var update = Builders <Organisation> .Update
                         .Set(organisaion => organisaion.Details, organisationIn)
                         .CurrentDate(o => o.UpdatedAt);

            try
            {
                _logger.LogInformation($"Trying to update organisation with id {id}");
                var o = _organisations.UpdateOne(filter, update);
                var organisationUpdatedId = o.UpsertedId;
                if (o.ModifiedCount == 1)
                {
                    _logger.LogInformation($"Updated successfully");
                    return(true);
                }
                throw new Exception("Update request completed but modified count does not equal 1.");
            }
            catch (MongoException ex)
            {
                _logger.LogError($"Error trying to update the record with id {id}: {ex.Message}");
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error: {ex.Message}");
            }
            _logger.LogInformation($"Did not update record {id}");
            throw new Exception("Error. Something went wrong and record was not updated.");
        }
示例#2
0
        public async Task ManageOrganisationHandler_OrganisationNotExists_CreateOrganisaton()
        {
            var userId  = Guid.NewGuid();
            var request = new ManageOrganisationRequest
            {
                Name                = "Test",
                OrganisationType    = "Test",
                OrganisationUkprn   = 10003000,
                RoATPApproved       = true,
                CreatedBy           = Guid.NewGuid(),
                PrimaryContactEmail = "*****@*****.**"
            };
            var organisationDetails = new OrganisationDetails
            {
                TradingName   = "Trading name",
                CompanyNumber = "12322322",
                CharityNumber = "2232332",
                Address1      = "T1",
                Address2      = "T2",
                Address3      = "T3",
                City          = "Test",
                Postcode      = "DD12TT"
            };

            request.OrganisationDetails = organisationDetails;
            _organisationRepository.Setup(x => x.GetOrganisationByName(It.IsAny <string>())).ReturnsAsync(() => null);
            _organisationRepository.Setup(x => x.CreateOrganisation(It.IsAny <Organisation>())).ReturnsAsync(() => Guid.NewGuid());

            var result = await _handler.Handle(request, new CancellationToken());

            result.Should().NotBeNull();
        }
示例#3
0
        public IActionResult Update(string id, [FromBody] OrganisationDetails organisationDetailsIn)
        {
            id = id.ToLower();

            OrganisationResponse.Success = false;

            if (organisationDetailsIn == null)
            {
                OrganisationResponse.Message = "Organisation submitted was null.";
                return(BadRequest(new[] { OrganisationResponse }));
            }

            if (!ModelState.IsValid)
            {
                OrganisationResponse.Message = $"Not all fields were supplied! {ModelState}";
                return(BadRequest(new[] { OrganisationResponse }));
            }

            try
            {
                var existing = _organisationsService.Get(id);

                if (existing == null)
                {
                    OrganisationResponse.Message = "Organisation record not found";
                    return(NotFound(new[] { OrganisationResponse }));
                }

                var updated           = _organisationsService.Update(id, organisationDetailsIn);
                var organisationFound = new List <Organisation>()
                {
                    _organisationsService.Get(id)
                };

                OrganisationResponse.Data = organisationFound;
                if (!updated)
                {
                    OrganisationResponse.NumberOfRecordsFound = organisationFound.Count;
                    OrganisationResponse.Message = "Update didn't work!";
                    return(BadRequest(new[] { OrganisationResponse }));
                }
                OrganisationResponse.Success = true;
                OrganisationResponse.NumberOfRecordsFound = organisationFound.Count;
                OrganisationResponse.Message = "Organisation record updated";
                return(Ok(new[] { OrganisationResponse }));
            }
            catch (MongoException ex)
            {
                _logger.LogDebug($"Error updating organisation record in the DB: {ex.Message}");
            }
            catch (Exception ex)
            {
                _logger.LogDebug($"Error: {ex.Message}");
            }
            _logger.LogInformation("Error: update request cannot be handled, bad request.");
            return(BadRequest());
        }
示例#4
0
        public void Validate()
        {
            OrganisationDetails?.Validate();
            PrincipalAuthority?.Validate();
            AlternativeBusinessRepresentatives?.Validate();
            DirectorOrPartner?.Validate();
            NamedIndividuals?.Validate();
            Organisation?.Validate();

            IsValid = OrganisationDetails != null && OrganisationDetails.IsValid &&
                      PrincipalAuthority != null && PrincipalAuthority.IsValid &&
                      AlternativeBusinessRepresentatives != null && AlternativeBusinessRepresentatives.IsValid &&
                      DirectorOrPartner != null && DirectorOrPartner.IsValid &&
                      NamedIndividuals != null && NamedIndividuals.IsValid &&
                      Organisation != null && Organisation.IsValid;
        }