Exemplo n.º 1
0
        private Program DoCreate(DraftProgram draftProgram, ProgramServiceValidationEntity validationEntity)
        {
            Contract.Requires(draftProgram != null, "The draft program must not be null.");
            validator.ValidateCreate(validationEntity);
            var program = new Program
            {
                Description     = draftProgram.Description,
                EndDate         = draftProgram.EndDate,
                Name            = draftProgram.Name,
                ParentProgramId = draftProgram.ParentProgramId,
                ProgramType     = null,
                ProgramStatusId = draftProgram.ProgramStatusId,
                StartDate       = draftProgram.StartDate,
                OwnerId         = draftProgram.OwnerOrganizationId
            };

            SetGoals(draftProgram.GoalIds, program);
            SetPointOfContacts(draftProgram.ContactIds, program);
            SetThemes(draftProgram.ThemeIds, program);
            SetRegions(draftProgram.RegionIds, program);
            SetCategories(draftProgram.FocusCategoryIds, program);
            SetObjectives(draftProgram.JustificationObjectiveIds, program);
            SetWebsitesToCreate(draftProgram.Websites, program, draftProgram);

            Debug.Assert(draftProgram.Audit != null, "The audit must not be null.");
            draftProgram.Audit.SetHistory(program);
            this.Context.Programs.Add(program);
            return(program);
        }
Exemplo n.º 2
0
        public void TestConstructor_NullListsOfIds()
        {
            var userId              = 1;
            var name                = "name";
            var description         = "description";
            var startDate           = DateTimeOffset.UtcNow.AddDays(-1.0);
            var endDate             = DateTime.UtcNow.AddDays(1.0);
            var ownerOrganizationId = 2;
            var parentProgramId     = 3;
            var programStatusId     = ProgramStatus.Active.Id;

            var user    = new User(userId);
            var program = new DraftProgram(
                createdBy: user,
                name: name,
                description: description,
                startDate: startDate,
                endDate: endDate,
                ownerOrganizationId: ownerOrganizationId,
                parentProgramId: parentProgramId,
                goalIds: null,
                pointOfContactIds: null,
                themeIds: null,
                regionIds: null,
                categoryIds: null,
                objectiveIds: null,
                websites: null
                );

            Assert.IsNotNull(program.GoalIds);
            Assert.IsNotNull(program.ThemeIds);
            Assert.IsNotNull(program.ContactIds);
            Assert.IsNotNull(program.RegionIds);
            Assert.IsNotNull(program.Websites);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new program in the ECA system with a status of draft.
        /// </summary>
        /// <param name="draftProgram">The draft program.</param>
        /// <returns>The saved program.</returns>
        public Program Create(DraftProgram draftProgram)
        {
            var regionTypeIds = GetLocationTypeIds(draftProgram.RegionIds);

            this.logger.Trace("Retrieved region type by region ids [{0}].", String.Join(", ", draftProgram.RegionIds));

            var owner = GetOrganizationById(draftProgram.OwnerOrganizationId);

            this.logger.Trace("Retrieved owner organization by id [{0}].", draftProgram.OwnerOrganizationId);

            var ownerOfficeSettings = officeService.GetOfficeSettings(owner.OrganizationId);

            this.logger.Trace("Retrieved office settings for owner organization with id [{0}].", owner.OrganizationId);

            var     parentProgramId = draftProgram.ParentProgramId;
            Program parentProgram   = parentProgramId.HasValue ? GetProgramEntityById(draftProgram.ParentProgramId.Value) : null;

            var inactiveRegionIds = GetLocationsById(draftProgram.RegionIds).Where(x => !x.IsActive).Select(x => x.LocationId).ToList();

            var allowedThemeIds = CreateGetAllowedThemeIdsQuery(draftProgram.ThemeIds).ToList();

            this.logger.Trace("Loaded allowed theme ids [{0}] for program with id [{1}].", String.Join(", ", allowedThemeIds), draftProgram.Id);

            var allowedGoalIds = CreateGetAllowedGoalIdsQuery(draftProgram.GoalIds).ToList();

            this.logger.Trace("Loaded allowed goal ids [{0}] for program with id [{1}].", String.Join(", ", allowedGoalIds), draftProgram.Id);

            var program = DoCreate(draftProgram, GetValidationEntity(
                                       program: draftProgram,
                                       owner: owner,
                                       ownerOfficeSettings: ownerOfficeSettings,
                                       parentProgram: parentProgram,
                                       regionTypesIds: regionTypeIds,
                                       inactiveRegionIds: inactiveRegionIds,
                                       parentProgramParentPrograms: new List <OrganizationProgramDTO>(),
                                       allowedThemeIds: allowedThemeIds,
                                       allowedGoalIds: allowedGoalIds));

            this.logger.Trace("Created program.");

            return(program);
        }
Exemplo n.º 4
0
        public void TestConstructor()
        {
            var userId              = 1;
            var name                = "name";
            var description         = "description";
            var startDate           = DateTimeOffset.UtcNow.AddDays(-1.0);
            var endDate             = DateTime.UtcNow.AddDays(1.0);
            var ownerOrganizationId = 2;
            var parentProgramId     = 3;
            var goalIds             = new List <int> {
                10
            };
            var themeIds = new List <int> {
                20
            };
            var pointOfContactIds = new List <int> {
                30
            };
            var regionIds = new List <int> {
                40
            };
            var categoryIds = new List <int> {
                50
            };
            var objectiveIds = new List <int> {
                60
            };
            var websites = new List <WebsiteDTO> {
                new WebsiteDTO(null, "http://google.com")
            };

            var user    = new User(userId);
            var program = new DraftProgram(
                createdBy: user,
                name: name,
                description: description,
                startDate: startDate,
                endDate: endDate,
                ownerOrganizationId: ownerOrganizationId,
                parentProgramId: parentProgramId,
                goalIds: goalIds,
                pointOfContactIds: pointOfContactIds,
                themeIds: themeIds,
                regionIds: regionIds,
                categoryIds: categoryIds,
                objectiveIds: objectiveIds,
                websites: websites

                );

            Assert.AreEqual(user, program.Audit.User);
            DateTimeOffset.UtcNow.Should().BeCloseTo(program.Audit.Date, DbContextHelper.DATE_PRECISION);

            Assert.AreEqual(name, program.Name);
            Assert.AreEqual(description, program.Description);
            Assert.AreEqual(startDate, program.StartDate);
            Assert.AreEqual(endDate, program.EndDate);
            Assert.AreEqual(ownerOrganizationId, program.OwnerOrganizationId);
            Assert.AreEqual(parentProgramId, program.ParentProgramId);
            Assert.AreEqual(ProgramStatus.Draft.Id, program.ProgramStatusId);
            Assert.IsNull(program.RowVersion);

            CollectionAssert.AreEqual(goalIds, program.GoalIds);
            CollectionAssert.AreEqual(themeIds, program.ThemeIds);
            CollectionAssert.AreEqual(pointOfContactIds, program.ContactIds);
            CollectionAssert.AreEqual(regionIds, program.RegionIds);
            CollectionAssert.AreEqual(websites, program.Websites);
        }
Exemplo n.º 5
0
        private void SetWebsitesToCreate(List <WebsiteDTO> websiteList, Program program, DraftProgram draftProgram)
        {
            var distinctWebsites = websiteList.Select(x => x.Value).Distinct().ToList();
            var websites         = new List <Website>();

            foreach (string websiteValue in distinctWebsites)
            {
                var website = new Website {
                    WebsiteValue = websiteValue
                };
                draftProgram.Audit.SetHistory(website);
                websites.Add(website);
            }
            program.Websites = websites;
        }
Exemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="draftProgram"></param>
 /// <returns></returns>
 public Task <Program> CreateAsync(DraftProgram draftProgram)
 {
     Contract.Requires(draftProgram != null, "The draft program must not be null.");
     return(Task.FromResult <Program>(null));
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="draftProgram"></param>
 /// <returns></returns>
 public Program Create(DraftProgram draftProgram)
 {
     Contract.Requires(draftProgram != null, "The draft program must not be null.");
     return(null);
 }