Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="saveActions">The save actions.</param>
        /// <param name="context">The context to query</param>
        public PersonService(EcaContext context, IBusinessValidator <PersonServiceValidationEntity, PersonServiceValidationEntity> validator, List <ISaveAction> saveActions = null)
            : base(context, saveActions)
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(validator != null, "The validator must not be null.");
            this.validator = validator;

            throwIfLocationNotFound = (location, id) =>
            {
                if (location == null)
                {
                    throw new ModelNotFoundException(String.Format("The location entity with id [{0}] was not found.", id));
                }
            };
            throwValidationErrorIfParticipantSevisInfoIsLocked = (participant) =>
            {
                participant.ValidateSevisLock();
            };
            throwIfModelDoesNotExist = (id, instance, type) =>
            {
                if (instance == null)
                {
                    throw new ModelNotFoundException(String.Format("The model of type [{0}] with id [{1}] was not found.", type.Name, id));
                }
            };
        }
Пример #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">The db context</param>
 /// <param name="officeService">The office service.</param>
 /// <param name="validator">The project business validator.</param>
 /// <param name="saveActions">The context save actions.</param>
 public ProjectService(
     EcaContext context,
     IOfficeService officeService,
     IBusinessValidator <ProjectServiceCreateValidationEntity, ProjectServiceUpdateValidationEntity> validator,
     List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(validator != null, "The validator must not be null.");
     this.validator             = validator;
     this.officeService         = officeService;
     throwIfProjectDoesNotExist = (projectId, project) =>
     {
         if (project == null)
         {
             throw new ModelNotFoundException(String.Format("The project with id [{0}] does not exist.", projectId));
         }
     };
     throwIfParticipantTypeDoesNotExist = (participantType) =>
     {
         if (participantType == null)
         {
             throw new ModelNotFoundException("The participant type does not exist.");
         }
     };
 }
Пример #3
0
        public NoteService(ManagerLogbookContext context,
                           IBusinessValidator validator)

        {
            this.context   = context;
            this.validator = validator;
        }
Пример #4
0
 public ReviewService(ManagerLogbookContext context,
                      IBusinessValidator businessValidator,
                      IReviewEditor reviewEditor)
 {
     this.context           = context;
     this.businessValidator = businessValidator;
     this.reviewEditor      = reviewEditor;
 }
Пример #5
0
 /// <summary>
 /// Creates a new ProgramService with the given context to operator against.
 /// </summary>
 /// <param name="officeService">The office service.</param>
 /// <param name="context">The context to operate on.</param>
 /// <param name="saveActions">The save actions.</param>
 /// <param name="programServiceValidator">The program service validator.</param>
 public ProgramService(
     EcaContext context,
     IOfficeService officeService,
     IBusinessValidator <ProgramServiceValidationEntity, ProgramServiceValidationEntity> programServiceValidator,
     List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(programServiceValidator != null, "The program service validator must not be null.");
     Contract.Requires(officeService != null, "The office service must not be null.");
     this.validator     = programServiceValidator;
     this.officeService = officeService;
 }
Пример #6
0
        public ProductsBusinessComponent(IProductsRepository productsRepository,
                                         IBusinessValidator <string> productNameValidator,
                                         IBusinessValidator <Product> productValidator)
        {
            if (productsRepository == default(IProductsRepository))
            {
                throw new ArgumentException(INVALID_PRODUCTS_REPOSITORY);
            }

            if (productNameValidator == default(IBusinessValidator <string>) &&
                productValidator == default(IBusinessValidator <Product>))
            {
                throw new ArgumentException(INVALID_ARGUMENTS);
            }

            this.productsRepository   = productsRepository;
            this.productNameValidator = productNameValidator;
            this.productValidator     = productValidator;
        }
 /// <summary>
 /// Creates a new service instance with the given context and save actions.
 /// </summary>
 /// <param name="context">The context to perform crud operations against.</param>
 /// <param name="saveActions">The context save actions.</param>
 /// <param name="itineraryStopValidator">The business validator.</param>
 public ItineraryStopService(
     EcaContext context,
     IBusinessValidator <EcaItineraryStopValidationEntity, EcaItineraryStopValidationEntity> itineraryStopValidator,
     IBusinessValidator <ItineraryStopParticipantsValidationEntity, ItineraryStopParticipantsValidationEntity> itineraryStopParticipantsValidator,
     List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(itineraryStopValidator != null, "The itinerary stop validator must not be null.");
     Contract.Requires(itineraryStopParticipantsValidator != null, "The itinerary stop participant validator must not be null.");
     this.itineraryStopValidator             = itineraryStopValidator;
     this.itineraryStopParticipantsValidator = itineraryStopParticipantsValidator;
     throwIfModelDoesNotExist = (id, instance, type) =>
     {
         if (instance == null)
         {
             throw new ModelNotFoundException(String.Format("The [{0}] with id [{1}] does not exist.", type.Name, id));
         }
     };
     throwSecurityViolationIfDifferentProject = (userId, instance, projectId) =>
     {
         if (instance != null && instance.ProjectId != projectId)
         {
             throw new BusinessSecurityException(
                       String.Format("The user with id [{0}] attempted to edit an itinerary on a project with id [{1}] but should have been denied access.",
                                     userId,
                                     projectId));
         }
     };
     throwSecurityViolationIfDifferentItinerary = (userId, itineraryStopParticipants, itinerary) =>
     {
         if (itinerary != null && itinerary.ItineraryId != itineraryStopParticipants.ItineraryId)
         {
             throw new BusinessSecurityException(
                       String.Format("The user with id [{0}] attempted to edit an itinerary stop on a project with id [{1}] and itinerary with id [{2}] but should have been denied access.",
                                     userId,
                                     itineraryStopParticipants.ProjectId,
                                     itineraryStopParticipants.ItineraryId
                                     ));
         }
     };
 }
Пример #8
0
 /// <summary>
 /// Creates a new location service with the context to operate against.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="addressValidator">The address create and update validator.</param>
 /// <param name="locationValidator">The location validator.</param>
 /// <param name="saveActions">The save actions.</param>
 public LocationService(
     EcaContext context,
     IBusinessValidator <LocationValidationEntity, LocationValidationEntity> locationValidator,
     IBusinessValidator <EcaAddressValidationEntity, EcaAddressValidationEntity> addressValidator,
     List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(addressValidator != null, "The address validator must not be null.");
     Contract.Requires(locationValidator != null, "The location validator must not be null.");
     this.locationValidator       = locationValidator;
     this.addressValidator        = addressValidator;
     throwIfLocationsAlreadyExist = (ecaLocation, locations) =>
     {
         if (locations.Count() > 0)
         {
             throw new UniqueModelException(String.Format("The given location [{0}] already exists in the system.", ecaLocation.LocationName));
         }
     };
     throwIfEntityNotFound = (id, instance, t) =>
     {
         if (instance == null)
         {
             throw new ModelNotFoundException(String.Format("The model type [{0}] with Id [{1}] was not found.", t.Name, id));
         }
     };
     throwIfLocationNotFound = (id, location, locationTypeName) =>
     {
         if (location == null)
         {
             throw new ModelNotFoundException(String.Format("The [{0}] with id [{1}] was not found.", locationTypeName, id));
         }
     };
     throwIfLocationTypeDoesNotExist = (locationTypeId, locationType) =>
     {
         if (locationType == null)
         {
             throw new ModelNotFoundException(String.Format("The location type with id [{0}] does not exist.", locationTypeId));
         }
     };
 }
Пример #9
0
 /// <summary>
 /// Creates a new service instance with the given context and save actions.
 /// </summary>
 /// <param name="context">The context to perform crud operations against.</param>
 /// <param name="saveActions">The context save actions.</param>
 public ItineraryService(EcaContext context,
                         IBusinessValidator <AddedEcaItineraryValidationEntity, UpdatedEcaItineraryValidationEntity> ecaItineraryValidator,
                         IBusinessValidator <ItineraryParticipantsValidationEntity, ItineraryParticipantsValidationEntity> itineraryParticipantsValidator,
                         List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(ecaItineraryValidator != null, "The eca itienrary validator must not be null.");
     Contract.Requires(itineraryParticipantsValidator != null, "The itienrary participants validator must not be null.");
     this.ecaItineraryValidator          = ecaItineraryValidator;
     this.itineraryParticipantsValidator = itineraryParticipantsValidator;
     throwIfModelDoesNotExist            = (id, instance, type) =>
     {
         if (instance == null)
         {
             throw new ModelNotFoundException(String.Format("The [{0}] with id [{1}] does not exist.", type.Name, id));
         }
     };
     throwSecurityViolationIfDifferentProject = (userId, instance, projectId) =>
     {
         if (instance != null && instance.ProjectId != projectId)
         {
             throw new BusinessSecurityException(
                       String.Format("The user with id [{0}] attempted to edit an itinerary on a project with id [{1}] but should have been denied access.",
                                     userId,
                                     projectId));
         }
     };
     throwSecurityViolationIfParticipantsNotOnProject = (userId, participantIds, itineraryId, projectId) =>
     {
         if (participantIds.Count() > 0)
         {
             throw new BusinessSecurityException(
                       String.Format("The user with id [{0}] attempted to add participants to the itinerary with id [{1}] that do not exist on the project with id [{2}].",
                                     userId,
                                     itineraryId,
                                     projectId
                                     ));
         }
     };
 }
Пример #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context">Context to query</param>
 /// <param name="organizationValidator">The organization validator.</param>
 /// <param name="saveActions">The save actions.</param>
 public OrganizationService(EcaContext context, IBusinessValidator <OrganizationValidationEntity, OrganizationValidationEntity> organizationValidator, List <ISaveAction> saveActions = null)
     : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(organizationValidator != null, "The validator must not be null.");
     this.organizationValidator  = organizationValidator;
     throwIfOrganizationByIdNull = (orgId, org) =>
     {
         if (org == null)
         {
             throw new ModelNotFoundException(String.Format("The organization with id [{0}] was not found.", orgId));
         }
     };
     throwIfOrganizationTypeByIdNull = (orgTypeId, orgType) =>
     {
         if (orgType == null)
         {
             throw new ModelNotFoundException(String.Format("The organization type with id [{0}] was not found.", orgTypeId));
         }
     };
 }
        /// <summary>
        /// Creates a new ParticipantPersonService with the given context to operate against.
        /// </summary>
        /// <param name="saveActions">The save actions.</param>
        /// <param name="context">The context to operate against.</param>
        /// <param name="logger">The logger.</param>
        public ParticipantPersonService(EcaContext context, IBusinessValidator <Object, UpdatedParticipantPersonValidationEntity> participantPersonValidator, List <ISaveAction> saveActions = null) : base(context, saveActions)
        {
            Contract.Requires(context != null, "The context must not be null.");
            Contract.Requires(participantPersonValidator != null, "The participant person validator must not be null.");
            this.participantPersonValidator = participantPersonValidator;
            throwIfModelDoesNotExist        = (id, instance, type) =>
            {
                if (instance == null)
                {
                    throw new ModelNotFoundException(String.Format("The model of type [{0}] with id [{1}] was not found.", type.Name, id));
                }
            };
            throwSecurityViolationIfParticipantDoesNotBelongToProject = (userId, projectId, participant) =>
            {
                if (participant != null && participant.ProjectId != projectId)
                {
                    throw new BusinessSecurityException(
                              String.Format("The user with id [{0}] attempted to delete a participant with id [{1}] and project id [{2}] but should have been denied access.",
                                            userId,
                                            participant.ParticipantId,
                                            projectId));
                }
            };
            throwValidationErrorIfParticipantSevisInfoIsLocked = (participant) =>
            {
                if (participant.ParticipantPerson != null)
                {
                    var sevisStatusId = participant.ParticipantPerson.ParticipantPersonSevisCommStatuses.OrderByDescending(x => x.AddedOn).Select(x => x.SevisCommStatusId).FirstOrDefault();

                    if (participant != null && IndexOfInt(LOCKED_SEVIS_COMM_STATUSES, sevisStatusId) != -1)
                    {
                        var msg = String.Format("An update was attempted on participant with id [{0}] but should have failed validation.",
                                                participant.ParticipantId);

                        throw new EcaBusinessException(msg);
                    }
                }
            };
        }
Пример #12
0
 /// <summary>
 /// Creates a new ContactService with the given context to operate against.
 /// </summary>
 /// <param name="saveActions">The save actions.</param>
 /// <param name="context">The context to operate against.</param>
 public ContactService(EcaContext context, IBusinessValidator <AdditionalPointOfContactValidationEntity, object> pointOfContactValidator, List <ISaveAction> saveActions = null) : base(context, saveActions)
 {
     Contract.Requires(context != null, "The context must not be null.");
     Contract.Requires(pointOfContactValidator != null, "The point of contact validator must not be null.");
     this.pointOfContactValidator = pointOfContactValidator;
 }
 public LogbookService(ManagerLogbookContext context,
                       IBusinessValidator businessValidator)
 {
     this.context           = context;
     this.businessValidator = businessValidator;
 }
 public BusinessManager(IBusinessValidator <T> validator)
 {
     this.validator = validator;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="dataAdapter"></param>
 /// <param name="businessValidator"></param>
 /// <param name="loggerFactory"></param>
 public BusinessService(IDataAdapter dataAdapter, IBusinessValidator businessValidator, ILoggerFactory loggerFactory)
 {
     _businessValidator = businessValidator;
     _teams             = dataAdapter.GetRepository();
     _logger            = loggerFactory.CreateLogger <BusinessService>();
 }