private void SetWebsitesToUpdate(EcaProgram updatedProgram, Program program) { var websiteIds = updatedProgram.Websites.Select(x => x.Id).ToList(); var websitesToRemove = program.Websites.Where(x => !websiteIds.Where(y => y != null).Contains(x.WebsiteId)).ToList(); foreach (Website website in websitesToRemove) { program.Websites.Remove(website); Context.Websites.Remove(website); } var websitesToAdd = updatedProgram.Websites.Where(x => x.Id == null).ToList(); foreach (WebsiteDTO website in websitesToAdd) { var newWebsite = new Website { WebsiteValue = website.Value }; updatedProgram.Audit.SetHistory(newWebsite); program.Websites.Add(newWebsite); } var websitesToUpdate = program.Websites.Where(x => websiteIds.Contains(x.WebsiteId)).ToList(); foreach (Website website in websitesToUpdate) { var updatedWebsite = updatedProgram.Websites.Where(x => x.Id == website.WebsiteId).FirstOrDefault(); website.WebsiteValue = updatedWebsite.Value; updatedProgram.Audit.SetHistory(website); } }
public void TestConstructor_InvalidProgramStatusId() { var userId = 1; var programId = 10; 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 = -1; var user = new User(userId); var program = new EcaProgram( updatedBy: user, id: programId, name: name, description: description, startDate: startDate, endDate: endDate, ownerOrganizationId: ownerOrganizationId, parentProgramId: parentProgramId, programStatusId: programStatusId, programRowVersion: new byte[0], goalIds: null, pointOfContactIds: null, themeIds: null, regionIds: null, categoryIds: null, objectiveIds: null, websites: null ); }
private ProgramServiceValidationEntity GetValidationEntity( EcaProgram program, Organization owner, OfficeSettings ownerOfficeSettings, Program parentProgram, List <int> regionTypesIds, List <int> inactiveRegionIds, List <OrganizationProgramDTO> parentProgramParentPrograms, List <int> allowedThemeIds, List <int> allowedGoalIds) { return(new ProgramServiceValidationEntity( programId: program.Id, name: program.Name, description: program.Description, regionLocationTypeIds: regionTypesIds, inactiveRegionIds: inactiveRegionIds, contactIds: program.ContactIds, owner: owner, themeIds: program.ThemeIds, goalIds: program.GoalIds, regionIds: program.RegionIds, categoryIds: program.FocusCategoryIds, objectiveIds: program.JustificationObjectiveIds, parentProgramId: program.ParentProgramId, parentProgram: parentProgram, ownerOfficeSettings: ownerOfficeSettings, parentProgramParentPrograms: parentProgramParentPrograms, allowedThemeIds: allowedThemeIds, allowedGoalIds: allowedGoalIds )); }
/// <summary> /// Returns a business entity capable of updating system programs. /// </summary> /// <param name="user">The user making the change.</param> /// <returns>The EcaProgram business entity.</returns> public EcaProgram ToEcaProgram(Business.Service.User user) { Contract.Assert(this.RowVersion != null, "The row version must not be null."); var ecaProgram = new EcaProgram( updatedBy: user, id: this.Id, name: this.Name, description: this.Description, startDate: this.StartDate, endDate: this.EndDate, ownerOrganizationId: this.OwnerOrganizationId, parentProgramId: this.ParentProgramId, programStatusId: this.ProgramStatusId, programRowVersion: Convert.FromBase64String(this.RowVersion), goalIds: this.Goals, pointOfContactIds: this.Contacts, themeIds: this.Themes, regionIds: this.Regions, categoryIds: this.Categories, objectiveIds: this.Objectives, websites: GetWebsites() ); return(ecaProgram); }
/// <summary> /// Updates the system's program with the given updated program. /// </summary> /// <param name="updatedProgram">The updated program.</param> public async Task UpdateAsync(EcaProgram updatedProgram) { var programToUpdate = await GetProgramEntityByIdAsync(updatedProgram.Id); this.logger.Trace("Retrieved program with id [{0}].", updatedProgram.Id); if (programToUpdate != null) { var regionTypeIds = await GetLocationTypeIdsAsync(updatedProgram.RegionIds); this.logger.Trace("Retrieved region type by region ids [{0}].", String.Join(", ", updatedProgram.RegionIds)); var owner = GetOrganizationById(updatedProgram.OwnerOrganizationId); this.logger.Trace("Retrieved owner organization by id [{0}].", updatedProgram.OwnerOrganizationId); var ownerOfficeSettings = await officeService.GetOfficeSettingsAsync(owner.OrganizationId); this.logger.Trace("Retrieved office settings for owner organization with id [{0}].", owner.OrganizationId); var parentProgramId = updatedProgram.ParentProgramId; Program parentProgram = parentProgramId.HasValue ? await GetProgramEntityByIdAsync(updatedProgram.ParentProgramId.Value) : null; List <OrganizationProgramDTO> parentProgramParentPrograms = new List <OrganizationProgramDTO>(); if (parentProgram != null) { parentProgramParentPrograms = await GetParentProgramsAsync(parentProgram.ProgramId); } var inactiveRegionIds = await(GetNewInactiveProgramLocations(updatedProgram.Id, updatedProgram.RegionIds).Select(x => x.LocationId)).ToListAsync(); var allowedThemeIds = await CreateGetAllowedThemeIdsQuery(updatedProgram.ThemeIds).ToListAsync(); this.logger.Trace("Loaded allowed theme ids [{0}] for program with id [{1}].", String.Join(", ", allowedThemeIds), updatedProgram.Id); var allowedGoalIds = await CreateGetAllowedGoalIdsQuery(updatedProgram.GoalIds).ToListAsync(); this.logger.Trace("Loaded allowed goal ids [{0}] for program with id [{1}].", String.Join(", ", allowedGoalIds), updatedProgram.Id); DoUpdate(programToUpdate, updatedProgram, GetValidationEntity( program: updatedProgram, owner: owner, ownerOfficeSettings: ownerOfficeSettings, parentProgram: parentProgram, regionTypesIds: regionTypeIds, inactiveRegionIds: inactiveRegionIds, parentProgramParentPrograms: parentProgramParentPrograms, allowedThemeIds: allowedThemeIds, allowedGoalIds: allowedGoalIds)); this.logger.Trace("Performed update on program."); } else { throw new ModelNotFoundException(String.Format("The program with the given Id [{0}] was not found.", updatedProgram.Id)); } }
private void DoUpdate(Program programToUpdate, EcaProgram updatedProgram, ProgramServiceValidationEntity validationEntity) { Contract.Requires(updatedProgram != null, "The updated program must not be null."); validator.ValidateUpdate(validationEntity); programToUpdate.Description = updatedProgram.Description; programToUpdate.EndDate = updatedProgram.EndDate; programToUpdate.Name = updatedProgram.Name; programToUpdate.OwnerId = updatedProgram.OwnerOrganizationId; programToUpdate.ParentProgramId = updatedProgram.ParentProgramId; programToUpdate.ProgramStatusId = updatedProgram.ProgramStatusId; programToUpdate.RowVersion = updatedProgram.RowVersion; programToUpdate.StartDate = updatedProgram.StartDate; updatedProgram.Audit.SetHistory(programToUpdate); SetGoals(updatedProgram.GoalIds, programToUpdate); SetPointOfContacts(updatedProgram.ContactIds, programToUpdate); SetThemes(updatedProgram.ThemeIds, programToUpdate); SetRegions(updatedProgram.RegionIds, programToUpdate); SetCategories(updatedProgram.FocusCategoryIds, programToUpdate); SetObjectives(updatedProgram.JustificationObjectiveIds, programToUpdate); SetWebsitesToUpdate(updatedProgram, programToUpdate); }
public void TestConstructor_DistinctListOfIds() { var userId = 1; var programId = 10; 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 goalIds = new List <int> { 10, 10 }; var themeIds = new List <int> { 20, 20 }; var pointOfContactIds = new List <int> { 30, 30 }; var regionIds = new List <int> { 40, 40 }; var categoryIds = new List <int> { 50, 50 }; var objectiveIds = new List <int> { 60, 60 }; var rowVersion = new byte[1] { (byte)1 }; var websites = new List <WebsiteDTO> { new WebsiteDTO(null, "http://www.google.com"), new WebsiteDTO(null, "http://www.google.com") }; var user = new User(userId); var program = new EcaProgram( updatedBy: user, id: programId, name: name, description: description, startDate: startDate, endDate: endDate, ownerOrganizationId: ownerOrganizationId, parentProgramId: parentProgramId, programStatusId: programStatusId, programRowVersion: rowVersion, goalIds: goalIds, pointOfContactIds: pointOfContactIds, themeIds: themeIds, regionIds: regionIds, categoryIds: categoryIds, objectiveIds: objectiveIds, websites: websites ); CollectionAssert.AreEqual(goalIds.Distinct().ToList(), program.GoalIds); CollectionAssert.AreEqual(themeIds.Distinct().ToList(), program.ThemeIds); CollectionAssert.AreEqual(pointOfContactIds.Distinct().ToList(), program.ContactIds); CollectionAssert.AreEqual(regionIds.Distinct().ToList(), program.RegionIds); CollectionAssert.AreEqual(websites.Distinct().ToList(), program.Websites); }
public void TestConstructor() { var userId = 1; var programId = 10; 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 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 rowVersion = new byte[1] { (byte)1 }; var websites = new List <WebsiteDTO> { new WebsiteDTO(null, "http://www.google.com") }; var user = new User(userId); var program = new EcaProgram( updatedBy: user, id: programId, name: name, description: description, startDate: startDate, endDate: endDate, ownerOrganizationId: ownerOrganizationId, parentProgramId: parentProgramId, programStatusId: programStatusId, programRowVersion: rowVersion, 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(programId, program.Id); Assert.AreEqual(name, program.Name); Assert.AreEqual(description, program.Description); Assert.AreEqual(startDate, program.StartDate); Assert.AreEqual(endDate, program.EndDate); Assert.AreEqual(parentProgramId, program.ParentProgramId); Assert.AreEqual(ownerOrganizationId, program.OwnerOrganizationId); Assert.AreEqual(programStatusId, program.ProgramStatusId); CollectionAssert.AreEqual(goalIds, program.GoalIds); CollectionAssert.AreEqual(themeIds, program.ThemeIds); CollectionAssert.AreEqual(pointOfContactIds, program.ContactIds); CollectionAssert.AreEqual(regionIds, program.RegionIds); CollectionAssert.AreEqual(rowVersion, program.RowVersion); CollectionAssert.AreEqual(websites, program.Websites); }
/// <summary> /// /// </summary> /// <param name="updatedProgram"></param> /// <returns></returns> public Task UpdateAsync(EcaProgram updatedProgram) { Contract.Requires(updatedProgram != null, "The updated program must not be null."); return(Task.FromResult <object>(null)); }
/// <summary> /// /// </summary> /// <param name="updatedProgram"></param> public void Update(EcaProgram updatedProgram) { Contract.Requires(updatedProgram != null, "The updated program must not be null."); }