/// <summary> /// Creates and returns project /// </summary> /// <param name="draftProject">The project to create</param> /// <returns>The project that was created</returns> public Project Create(DraftProject draftProject) { var program = GetProgramById(draftProject.ProgramId); this.logger.Trace("Retrieved program by id {0}.", draftProject.ProgramId); validator.ValidateCreate(GetCreateValidationEntity(draftProject, program)); var project = DoCreate(draftProject, program); this.logger.Trace("Created project {0}.", project); return(project); }
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); }
private Location DoCreate(Location region, Location country, Location division, Location city, LocationType locationType, AdditionalLocation additionalLocation) { var validationEntity = GetLocationValidationEntity(additionalLocation, region, country, division, city); locationValidator.ValidateCreate(validationEntity); if (division == null && city != null && city.Division != null) { division = city.Division; } if (country == null && division != null && division.Country != null) { country = division.Country; } if (region == null && country != null && country.Region != null) { region = country.Region; } var newLocation = new Location { IsActive = true, City = city, Country = country, Division = division, Region = region, Latitude = additionalLocation.Latitude, Longitude = additionalLocation.Longitude, LocationName = additionalLocation.LocationName, LocationType = locationType, }; Context.Locations.Add(newLocation); additionalLocation.Audit.SetHistory(newLocation); return(newLocation); }
private Contact DoCreate(AdditionalPointOfContact pointOfContact) { var validationEntity = GetAdditionalPointOfContactValidationEntity(pointOfContact); pointOfContactValidator.ValidateCreate(validationEntity); var contact = new Contact(); Contract.Assert(!String.IsNullOrWhiteSpace(pointOfContact.FullName), "The point of contact must have a full name value."); contact.FullName = pointOfContact.FullName.Trim(); if (!string.IsNullOrWhiteSpace(pointOfContact.Position)) { contact.Position = pointOfContact.Position.Trim(); } foreach (var email in pointOfContact.EmailAddresses.Where(x => !String.IsNullOrWhiteSpace(x.Address))) { var newEmail = new EmailAddress { EmailAddressTypeId = email.EmailAddressTypeId, Address = email.Address.Trim(), IsPrimary = email.IsPrimary }; pointOfContact.Audit.SetHistory(newEmail); contact.EmailAddresses.Add(newEmail); Context.EmailAddresses.Add(newEmail); } foreach (var phoneNumber in pointOfContact.PhoneNumbers.Where(x => !String.IsNullOrWhiteSpace(x.Number))) { var newPhoneNumber = new PhoneNumber { Number = phoneNumber.Number.Trim(), Extension = phoneNumber.Extension.Trim(), PhoneNumberTypeId = phoneNumber.PhoneNumberTypeId, IsPrimary = phoneNumber.IsPrimary }; pointOfContact.Audit.SetHistory(newPhoneNumber); contact.PhoneNumbers.Add(newPhoneNumber); Context.PhoneNumbers.Add(newPhoneNumber); } pointOfContact.Audit.SetHistory(contact); this.Context.Contacts.Add(contact); return(contact); }
private Organization DoCreate(NewOrganization newOrganization, OrganizationType organizationType) { organizationValidator.ValidateCreate(GetOrganizationValidationEntity(newOrganization)); var organization = new Organization { Name = newOrganization.Name, Description = newOrganization.Description, OrganizationType = organizationType, OrganizationTypeId = newOrganization.OrganizationType, Website = newOrganization.Website, Status = "Active" }; SetOrganizationRoles(newOrganization.OrganizationRoles.ToList(), organization); SetPointOfContacts(newOrganization.PointsOfContact.ToList(), organization); newOrganization.Audit.SetHistory(organization); this.Context.Organizations.Add(organization); return(organization); }
private Itinerary DoCreate(AddedEcaItinerary addedItinerary, Project project, Location arrivalLocation, Location departureLocation) { ecaItineraryValidator.ValidateCreate(GetAddedEcaItineraryValidationEntity( addedItinerary: addedItinerary, project: project, arrivalLocation: arrivalLocation, departureLocation: departureLocation)); var itinerary = new Itinerary(); addedItinerary.Audit.SetHistory(itinerary); itinerary.ArrivalLocationId = arrivalLocation.LocationId; itinerary.DepartureLocationId = departureLocation.LocationId; itinerary.EndDate = addedItinerary.EndDate; itinerary.Name = addedItinerary.Name; itinerary.ProjectId = project.ProjectId; itinerary.StartDate = addedItinerary.StartDate; itinerary.ItineraryStatusId = ItineraryStatus.InProgress.Id; this.Context.Itineraries.Add(itinerary); return(itinerary); }
private Address DoCreateAddress <T>( T entity, AdditionalAddress <T> additionalAddress, ICollection <Address> existingAddresses, Location country, Location division, Location city) where T : class, IAddressable { logger.Info("Adding an additional address to the [{0}] entity with id [{1}].", typeof(T).Name, additionalAddress.GetAddressableEntityId()); addressValidator.ValidateCreate(ToEcaAddressValidationEntity(address: additionalAddress, country: country, division: division, city: city)); var address = additionalAddress.AddAddress(entity); Context.Addresses.Add(address); Context.Locations.Add(address.Location); additionalAddress.Create.SetHistory(address); additionalAddress.Create.SetHistory(address.Location); if (additionalAddress.IsPrimary) { SetAllAddressesNotPrimary(existingAddresses); } return(address); }
private ItineraryStop DoCreate(Itinerary itinerary, AddedEcaItineraryStop addedStop) { var validationEntity = GetEcaItineraryStopValidationEntity(itinerary: itinerary, ecaitineraryStop: addedStop); itineraryStopValidator.ValidateCreate(validationEntity); var update = new Update(addedStop.Audit.User); update.SetHistory(itinerary); var itineraryStop = new ItineraryStop(); itineraryStop.DateArrive = addedStop.ArrivalDate; itineraryStop.DateLeave = addedStop.DepartureDate; itineraryStop.DestinationId = addedStop.DestinationLocationId; itineraryStop.ItineraryId = addedStop.ItineraryId; itineraryStop.ItineraryStatusId = ItineraryStatus.InProgress.Id; itineraryStop.Name = addedStop.Name; itineraryStop.TimezoneId = addedStop.TimezoneId; addedStop.Audit.SetHistory(itineraryStop); Context.ItineraryStops.Add(itineraryStop); return(itineraryStop); }