public void UpdateOrganisation(OrganisationDto inputOrganisationDto)
        {
            if (inputOrganisationDto == null)
            {
                throw new Exception("No organisation specified.");
            }

            if (inputOrganisationDto.Id < 1)
            {
                throw new Exception("No organisation specified.");
            }

            var updatedOrganisation = GetOrganisationWithUpdatedFields(inputOrganisationDto);

            _timeKeeperRepo.UpdateOrganisationAsync(updatedOrganisation);
        }
Ejemplo n.º 2
0
        /// <summary>Check if this PowerOffice organisation contains any updates that should be copied to webCRM.</summary>
        public bool HasChangesRelevantToWebcrm(
            OrganisationDto webcrmOrganisation,
            PowerofficeConfiguration configuration)
        {
            if (PropertyHasChanged(webcrmOrganisation, configuration.OrganisationCodeFieldName, Code.ToString()))
            {
                return(true);
            }

            if (PropertyHasChanged(webcrmOrganisation, configuration.PrimaryDeliveryAddressFieldName, ConcatenatedPrimaryStreetAddress))
            {
                return(true);
            }

            return(HasRelevantChanges(webcrmOrganisation, configuration));
        }
        private Organisation GetOrganisationWithUpdatedFields(OrganisationDto inputDto)
        {
            var storedDto = _timeKeeperRepo.GetOrganisationAsync(inputDto.Id).Result;

            storedDto.Name      = inputDto.Name ?? storedDto.Name;
            storedDto.ManagerId = inputDto.ManagerId ?? storedDto.ManagerId;

            storedDto.FK_Parent_OrganisationId = inputDto.ParentOrganisationId;

            if (inputDto.ParentOrganisationId == 0 || inputDto.ParentOrganisationId == null)
            {
                storedDto.FK_Parent_OrganisationId = null;
            }

            return(storedDto);
        }
        public async Task <IActionResult> Add([FromForm] OrganisationDto inputOrganisation)
        {
            var user = await _userManager.GetUserAsync(User);

            try
            {
                _service.AddOrganisation(inputOrganisation.Name, user);
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return(View());
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public void Test_Passing_Valid_Values()
        {
            // ARRANGE
            IOrganisation organisation = new Organisation(
                id: Guid.NewGuid(),
                code: "CBC",
                name: "County Bridge Club",
                bgColour: "000000");

            // ACT
            OrganisationDto organisationDto = OrganisationDto.ToDto(organisation);

            // ASSERT
            Assert.AreEqual(organisation.Id, organisationDto.Id);
            Assert.AreEqual(organisation.Code, organisationDto.Code);
            Assert.AreEqual(organisation.Name, organisationDto.Name);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostOrganisation([FromBody] Organisation organisation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            OrganisationDto organisationDto = new OrganisationDto
            {
                OrganisationName = organisation.OrganisationName,
                Email            = organisation.Email,
                ImageUrl         = organisation.LogoUrl
            };

            await _service.CreateCredentials(organisation);

            return(Ok(organisationDto));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> CreateOrganisation([FromBody] OrganisationDto organisation)
        {
            if (organisation == null)
            {
                return(BadRequest());
            }
            var org = _mapper.Map <Organisation>(organisation);

            _organisationRepository.AddOrganisation(org);
            if (!await _organisationRepository.Save())
            {
                throw new Exception("Organisation creation failed");
            }
            var createdOrg = _mapper.Map <OrganisationDto>(org);

            return(CreatedAtRoute("GetOrganisation", new { key = org.Key }, createdOrg));
        }
Ejemplo n.º 8
0
        public void Test_With_Valid_List_Of_Committees()
        {
            // ARRANGE
            Guid         paramId       = Guid.NewGuid();
            const string paramCode     = "CBC";
            const string paramName     = "County Bridge Club";
            const string paramBgColour = "000000";

            OrganisationDto organisationDto = new OrganisationDto(
                id: paramId,
                code: paramCode,
                name: paramName,
                bgColour: paramBgColour);

            IList <CommitteeDto> paramCommittees = new List <CommitteeDto>
            {
                new CommitteeDto(
                    id: Guid.NewGuid(),
                    organisationId: organisationDto.Id,
                    name: "TSC",
                    description: "Tournament Sub-Committee",
                    organisation: organisationDto)
            };

            organisationDto.SetPrivatePropertyValue(
                propName: nameof(OrganisationDto.Committees),
                value: paramCommittees);

            // ACT
            IOrganisationWithCommittees organisationWithCommittees =
                organisationDto.ToDomainWithCommittees();

            // ASSERT
            Assert.AreEqual(paramId, organisationWithCommittees.Id);
            Assert.AreEqual(paramCode, organisationWithCommittees.Code);
            Assert.AreEqual(paramName, organisationWithCommittees.Name);
            Assert.AreEqual(paramBgColour, organisationWithCommittees.BgColour);
            Assert.IsNotNull(organisationWithCommittees.Committees);
            Assert.AreEqual(1, organisationWithCommittees.Committees.Count);

            ICommittee committee = organisationWithCommittees.Committees[0];

            Assert.IsNotNull(committee);
            Assert.IsNotNull(committee.Organisation);
            Assert.AreEqual(paramId, committee.Organisation.Id);
        }
Ejemplo n.º 9
0
        public void Test_That_Null_List_Of_Committees_Throws_Exception()
        {
            // ARRANGE
            Guid         paramId       = Guid.NewGuid();
            const string paramCode     = "CBC";
            const string paramName     = "County Bridge Club";
            const string paramBgColour = "000000";

            OrganisationDto organisationDto = new OrganisationDto(
                id: paramId,
                code: paramCode,
                name: paramName,
                bgColour: paramBgColour);

            // ACT
            _ = organisationDto.ToDomainWithCommittees();
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        public async Task CreateOrganisationAsync(
            IWho who,
            IAuditHeaderWithAuditDetails auditHeader,
            IOrganisation organisation)
        {
            this.logger.ReportEntry(
                who,
                new { Organisation = organisation });

            OrganisationDto dto = OrganisationDto.ToDto(organisation);

            this.context.Organisations.Add(dto);
            await this.context.SaveChangesAsync().ConfigureAwait(false);

            Audit.AuditCreate(auditHeader, dto, dto.Id);

            this.logger.ReportExit(who);
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> PostOrganisation([FromBody] OrganisationDto organisation)
        {
            try
            {
                var newOrganisation = await Mediator.Send(new CreateOrganisationCommand(organisation.Name, organisation.MasterEmail));

                return(Ok(newOrganisation));
            }
            catch (ThisAppException ex)
            {
                Logger.LogError($"GetOrganisationsForLoggedInUser, {ex.StatusCode}, {ex.Message}", ex);
                return(StatusCode(ex.StatusCode, ex.Message));
            }
            catch (System.Exception ex)
            {
                Logger.LogError($"GetOrganisationsForLoggedInUser, {StatusCodes.Status500InternalServerError}", ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, Messages.Err500));
            }
        }
Ejemplo n.º 12
0
        public void Test_Basic_Constructor()
        {
            // ARRANGE
            Guid         paramId   = Guid.NewGuid();
            const string paramCode = "CBC";
            const string paramName = "County Bridge Club";

            // ACT
            OrganisationDto dto = new OrganisationDto(
                id: paramId,
                code: paramCode,
                name: paramName,
                bgColour: "000000");

            // ASSERT
            Assert.AreEqual(paramId, dto.Id);
            Assert.AreEqual(paramCode, dto.Code);
            Assert.AreEqual(paramName, dto.Name);
        }
Ejemplo n.º 13
0
        /// <inheritdoc/>
        public async Task UpdateOrganisationAsync(
            IWho who,
            IAuditHeaderWithAuditDetails auditHeader,
            IOrganisation organisation)
        {
            this.logger.ReportEntry(
                who,
                new { Organisation = organisation });

            OrganisationDto dto      = OrganisationDto.ToDto(organisation);
            OrganisationDto original = await this.context.FindAsync <OrganisationDto>(organisation.Id);

            Audit.AuditUpdate(auditHeader, dto.Id, original, dto);

            this.context.Entry(original).CurrentValues.SetValues(dto);
            await this.context.SaveChangesAsync().ConfigureAwait(false);

            this.logger.ReportExit(who);
        }
Ejemplo n.º 14
0
        public void Test_Passing_Valid_Values()
        {
            // ARRANGE
            IOrganisation organisation = new Organisation(
                id: Guid.NewGuid(),
                shortName: "Short",
                mediumName: "Medium",
                longName: "Long",
                code: "Code");

            // ACT
            OrganisationDto organisationDto = OrganisationDto.ToDto(organisation);

            // ASSERT
            Assert.AreEqual(organisation.Id, organisationDto.Id);
            Assert.AreEqual(organisation.ShortName, organisationDto.ShortName);
            Assert.AreEqual(organisation.MediumName, organisationDto.MediumName);
            Assert.AreEqual(organisation.LongName, organisationDto.LongName);
            Assert.AreEqual(organisation.Code, organisationDto.Code);
        }
        private void AuthorizePut(HttpActionContext actionContext)
        {
            int organiserId;

            string controller = actionContext.ControllerContext.ControllerDescriptor.ControllerName;

            switch (controller)
            {
            case "Organisation":
                OrganisationDto organisationDto = (OrganisationDto)actionContext.ActionArguments["dto"];
                Organisation    organisation    = this.Organisations.Get(organisationDto.Id);
                organiserId = organisation.OrganiserId;
                break;

            case "Subtheme":
                SubthemeDto subthemeDto = (SubthemeDto)actionContext.ActionArguments["dto"];
                Subtheme    subtheme    = this.Subthemes.Get(subthemeDto.Id);
                organiserId = subtheme.OrganiserId;
                break;

            case "Theme":
                ThemeDto themeDto = (ThemeDto)actionContext.ActionArguments["dto"];
                Theme    theme    = this.Themes.Get(themeDto.Id);
                organiserId = themeDto.OrganiserId;
                break;

            case "Session":
                SessionDto sessionDto = (SessionDto)actionContext.ActionArguments["dto"];
                Session    session    = this.Sessions.Get(sessionDto.Id, collections: true);

                this.AuthorizeOrganiser(session.Organisers);

                return;

            default:        // will be unauthorized
                organiserId = -1;
                break;
            }

            this.AuthorizeOrganiser(organiserId);
        }
Ejemplo n.º 16
0
        public void TestShouldSynchronise(
            string status,
            string type,
            IEnumerable <string> acceptedStatuses,
            IEnumerable <string> acceptedTypes,
            bool expectedResult)
        {
            var organisation = new OrganisationDto();

            organisation.OrganisationStatus = status;
            organisation.OrganisationType   = type;

            var configuration = new PowerofficeConfiguration();

            configuration.AcceptedOrganisationStatuses = acceptedStatuses;
            configuration.AcceptedOrganisationTypes    = acceptedTypes;

            bool actualResult = organisation.ShouldSynchronise(configuration);

            Assert.Equal(expectedResult, actualResult);
        }
        public async Task TestUpdateOrganisationWithValidId()
        {
            // Arrange
            var organisation = new Organisation
            {
                Id              = 1,
                Name            = "Test1",
                Address         = "55 Symonds",
                Description     = "UoA Accomodation",
                Status          = OrganisationStatus.Active,
                Classifications = new List <string> {
                    "Classficiation", "Classification1"
                }
            };

            // Arrange
            var organisationUpdated = new OrganisationDto
            {
                Id              = 1,
                Name            = "Test12",
                Address         = "55 Symmonds",
                Description     = "UoA Accomodation",
                Status          = OrganisationStatus.Active,
                Classifications = new List <string> {
                    "Classficiation", "Classification1"
                }
            };

            _mockOrganisationRepository.Setup(x => x.GetByIdAsync(1))
            .Returns(Task.FromResult(organisation));

            _mockOrganisationRepository.Setup(x => x.Update(It.IsAny <Organisation>())).Verifiable();

            // Act
            var response = await _organisationsController.UpdateOrganisation(organisationUpdated, 1);

            // Assert
            Assert.IsInstanceOf <NoContentResult>(response);
            _mockOrganisationRepository.Verify();
        }
Ejemplo n.º 18
0
        private async Task CreateOrganisation()
        {
            //Arrange
            var org = new OrganisationDto()
            {
                MasterEmail = "*****@*****.**",
                Name        = "Integration Tester"
            };
            var data = new StringContent(JsonConvert.SerializeObject(org), Encoding.UTF8, "application/json");

            //Act
            var response = await Client.PostAsync("/api/oranisations", data);

            //Assert
            response.IsSuccessStatusCode.ShouldBeTrue();
            string apiResponse = await response.Content.ReadAsStringAsync();

            Organisation = JsonConvert.DeserializeObject <OrganisationDto>(apiResponse);
            Organisation.Id.ShouldBeGreaterThan(0);
            Organisation.MasterEmail.ShouldBe(org.MasterEmail);
            Organisation.Name.ShouldBe(org.Name);
        }
Ejemplo n.º 19
0
        public void Test_That_Null_List_Of_Meetings_Throws_Exception()
        {
            Guid         paramId          = Guid.NewGuid();
            const string paramName        = "TSC";
            const string paramDescription = "Tournament Sub-Committee";

            OrganisationDto organisationDto = new OrganisationDto(
                id: Guid.NewGuid(),
                code: "CBC",
                name: "County Bridge Club",
                bgColour: "000000");

            CommitteeDto committeeDto = new CommitteeDto(
                id: paramId,
                organisationId: organisationDto.Id,
                name: paramName,
                description: paramDescription,
                organisation: organisationDto);

            // ACT
            _ = committeeDto.ToDomainWithMeetings();
        }
Ejemplo n.º 20
0
        public async Task TestUpdateOrganisationValidInput()
        {
            // Arrange
            var organisation = new Organisation
            {
                Id              = 1,
                Name            = "Test1",
                Address         = "55 Symonds",
                Description     = "UoA Accomodation",
                Status          = OrganisationStatus.Active,
                Classifications = new List <string> {
                    "Classficiation", "Classification1"
                }
            };

            var organisationUpdated = new OrganisationDto
            {
                Id              = 1,
                Name            = "Test12",
                Address         = "55 Symmonds",
                Description     = "UoA Accomodation",
                Status          = OrganisationStatus.Active,
                Classifications = new List <string> {
                    "Classficiation", "Classification1"
                }
            };

            _mockOrganisationRepository.Setup(x => x.GetByIdAsync(1))
            .Returns(Task.FromResult(organisation));

            _mockOrganisationRepository.Setup(x => x.Update(It.IsAny <Organisation>())).Verifiable();


            //Act
            await _organisationService.UpdateOrganisation(organisationUpdated);

            // Assert
            _mockOrganisationRepository.Verify();
        }
Ejemplo n.º 21
0
        public async Task <OrganisationDto> CreateOrganisation(OrganisationDto organisationDto, string userId)
        {
            var organisation = new Organisations
            {
                Active           = true,
                Address          = organisationDto.Address,
                Comments         = organisationDto.Comments,
                ContactEmail     = organisationDto.Email,
                ContactPhone     = organisationDto.Phone,
                CreatedBy        =,
                CreatedOn        = DateTimeHelper.Instance.GetCurrentDate(),
                Description      = organisationDto.Description,
                LastActivityType = "I",
                Name             = organisationDto.Name
            };

            _organisationResposiory.CreateOrganisation(organisation);
            await _organisationResposiory.SaveAsync();

            return(organisationDto);
        }
    }
        public async Task TestUpdateOrganisationWithInvalidId()
        {
            // Arrange
            var organisation = new OrganisationDto
            {
                Id              = 1,
                Name            = "Test1",
                Address         = "55 Symonds",
                Description     = "UoA Accomodation",
                Status          = OrganisationStatus.Active,
                Classifications = new List <string> {
                    "Classficiation", "Classification1"
                }
            };

            // Act
            var response = await _organisationsController.UpdateOrganisation(organisation, 2);

            // Assert
            Assert.IsInstanceOf <BadRequestResult>(response);
            _mockOrganisationRepository.Verify(x => x.Update(It.IsAny <Organisation>()), Times.Never);
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Create([FromBody] OrganisationDto org)
        {
            if (org == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                await _organisation.Create(org);

                if (await _organisation.Save())
                {
                    var reqestedOrg = Mapper.Map <Organisations>(org);
                    var savedOrg    = Mapper.Map <OrganisationDto>(reqestedOrg);
                    return(CreatedAtRoute("GetOrg", new { id = savedOrg.Id }, savedOrg));
                }
                else
                {
                    return(StatusCode(500, "Server Error,"));
                }
            }
            return(BadRequest(ModelState));
        }
Ejemplo n.º 24
0
        public void Test_WithNull_Committee_Throws_Exception()
        {
            // ARRANGE
            OrganisationDto organisationDto = new OrganisationDto(
                id: Guid.NewGuid(),
                code: "CBC",
                name: "County Bridge Club",
                bgColour: "000000");
            CommitteeDto committeeDto = new CommitteeDto(
                id: Guid.NewGuid(),
                organisationId: organisationDto.Id,
                name: "TSC",
                description: "Tournament Sub-Committee",
                organisation: organisationDto);
            MeetingDto meetingDto = new MeetingDto(
                Guid.NewGuid(),
                committeeId: committeeDto.Id,
                meetingDateTime: new DateTime(2019, 12, 30, 19, 15, 00),
                committee: null !);

            // ACT
            _ = meetingDto.ToDomain();
        }
Ejemplo n.º 25
0
        /// <inheritdoc/>
        public async Task CreateAsync(
            IWho who,
            IAuditHeaderWithAuditDetails auditHeader,
            IOrganisation organisation)
        {
            this.logger.LogTrace(
                "ENTRY {Method}(who, organisation) {@Who} {@Organisation}",
                nameof(this.CreateAsync),
                who,
                organisation);

            OrganisationDto dto = OrganisationDto.ToDto(organisation);

            this.context.Organisations.Add(dto);
            await this.context.SaveChangesAsync().ConfigureAwait(false);

            Audit.AuditCreate(auditHeader, dto, dto.Id);

            this.logger.LogTrace(
                "EXIT {Method}(who) {@Who}",
                nameof(this.CreateAsync),
                who);
        }
Ejemplo n.º 26
0
        public async Task TestCreateOrganisationValidInput()
        {
            //Arrange
            var organisationDto = new OrganisationDto
            {
                Name            = "Test1",
                Address         = "55 Symonds",
                Description     = "UoA Accomodation",
                Status          = OrganisationStatus.Active,
                Classifications = new List <string> {
                    "Classficiation", "Classification1"
                }
            };

            _mockOrganisationRepository.Setup(x => x.InsertAsync(It.IsAny <Organisation>())).Returns(Task.FromResult(1));

            //Act
            var id = await _organisationService.CreateOrganisation(organisationDto);

            //Assert
            Assert.AreEqual(0, id);
            _mockOrganisationRepository.Verify(x => x.InsertAsync(It.IsAny <Organisation>()), Times.Once);
        }
Ejemplo n.º 27
0
        private async Task SaveOrginisationDirect()
        {
            try
            {
                OrgData = await Mediator.Send(new UpdateOrganisationCommand(OrgData.Id, OrgData.Name, OrgData.MasterEmail));

                StatusMessage = "Organisation Saved";
            }
            catch (ThisAppException ex)
            {
                SiteLogger.LogError(this.ToString(), ex);
                StatusMessage = $"Save Organisation failed: {ex.Message}";
            }
            catch (System.Exception ex)
            {
                SiteLogger.LogError(this.ToString(), ex);
                StatusMessage = $"Save Organisation failed: {Messages.Err500}";
            }
            //finally
            //{
            //      TODO: functionality to associate this user with multiple organisations.
            //    await GetOrginisations();
            //}
        }
Ejemplo n.º 28
0
        public async Task <bool> AddAppointmentAsync(AppointmentDto dto)
        {
            m_Logger.Information($"{nameof(AddAppointmentAsync)} Invoked");
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            UserDto userDto = await m_AppointmentAccess.GetUserAsync(dto.UserId).ConfigureAwait(false);

            OrganisationDto organisationDto = await m_AppointmentAccess.GetOrganisationAsync(dto.OrganisationId).ConfigureAwait(false);

            bool deferAppointment = false;

            if (userDto == null)
            {
                PublishFeedMeEvent <int, UserDto>(dto.UserId);
                deferAppointment = true;
            }

            if (organisationDto == null)
            {
                PublishFeedMeEvent <int, OrganisationDto>(dto.OrganisationId);
                deferAppointment = true;
            }

            if (deferAppointment)
            {
                // Stick the task into a table for later.
                PostAppointmentToTableStorage(dto);
                return(false);
            }

            int id = await m_AppointmentAccess.AddAppointmentAsync(dto).ConfigureAwait(false);

            return(id != 0);
        }
Ejemplo n.º 29
0
        public void Test_Basic_Constructor()
        {
            // ARRANGE
            Guid         paramId         = Guid.NewGuid();
            const string paramShortName  = "Short";
            const string paramMediumName = "Medium";
            const string paramLongName   = "Long";
            const string paramCode       = "Code";

            // ACT
            OrganisationDto dto = new OrganisationDto(
                id: paramId,
                shortName: paramShortName,
                mediumName: paramMediumName,
                longName: paramLongName,
                code: paramCode);

            // ASSERT
            Assert.AreEqual(paramId, dto.Id);
            Assert.AreEqual(paramShortName, dto.ShortName);
            Assert.AreEqual(paramMediumName, dto.MediumName);
            Assert.AreEqual(paramLongName, dto.LongName);
            Assert.AreEqual(paramCode, dto.Code);
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> PutOrganisation(long organisationId, [FromBody] OrganisationDto organisation)
        {
            try
            {
                if (organisationId != organisation.Id)
                {
                    throw new ThisAppException(StatusCodes.Status409Conflict, "Organisation Id not matching.");
                }

                var updatedOrganisation = await Mediator.Send(new UpdateOrganisationCommand(organisation.Id, organisation.Name, organisation.MasterEmail));

                return(Ok(updatedOrganisation));
            }
            catch (ThisAppException ex)
            {
                Logger.LogError($"GetOrganisationsForLoggedInUser, {ex.StatusCode}, {ex.Message}", ex);
                return(StatusCode(ex.StatusCode, ex.Message));
            }
            catch (System.Exception ex)
            {
                Logger.LogError($"GetOrganisationsForLoggedInUser, {StatusCodes.Status500InternalServerError}", ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, Messages.Err500));
            }
        }