/// <summary>
        /// Writes to the console the invalid exchange visitor that failed validation.
        /// </summary>
        /// <param name="exchangeVisitor">The exchange visitor that failed validation.</param>
        public void NotifyInvalidExchangeVisitor(ExchangeVisitor exchangeVisitor)
        {
            var participantId = exchangeVisitor != null && exchangeVisitor.Person != null ? exchangeVisitor.Person.ParticipantId : -1;
            var personId      = exchangeVisitor != null && exchangeVisitor.Person != null ? exchangeVisitor.Person.PersonId : -1;

            Console.WriteLine(String.Format("ExchangeVisitor with participant id [{0}] and person id [{1}] failed validation.", participantId, personId));
        }
 /// <summary>
 /// Returns true, if the given exchange visitor can be added to this batch; otherwise, false.
 /// </summary>
 /// <param name="exchangeVisitor">The exchange visitor to add.</param>
 /// <returns>True, if the given exchange visitor can be added to this batch; otherwise false.</returns>
 public bool CanAccomodate(SevisGroupedParticipantDTO participant, ExchangeVisitor exchangeVisitor, string sevisUsername, string sevisOrgId, ExchangeVisitor previouslySubmittedExchangeVisitor = null)
 {
     Contract.Requires(exchangeVisitor != null, "The exchange visitor must not be null.");
     Contract.Requires(participant != null, "The participant must not be null.");
     Contract.Requires(participant.ParticipantId == exchangeVisitor.Person.ParticipantId, "The participant must belong to the exchange visitor.");
     if (this.SevisUsername != sevisUsername || this.SevisOrgId != sevisOrgId)
     {
         return(false);
     }
     if (String.IsNullOrWhiteSpace(exchangeVisitor.SevisId))
     {
         var count          = this.SEVISBatchCreateUpdateEV.CreateEV == null ? 0 : this.SEVISBatchCreateUpdateEV.CreateEV.Count();
         var addedItemCount = 1;
         return(count + addedItemCount <= this.MaxCreateExchangeVisitorRecordsPerBatch);
     }
     else
     {
         if (previouslySubmittedExchangeVisitor == null)
         {
             throw new NotSupportedException("The previously submitted exchange visitor must be supplied, since the exchange visitor has a sevis id.");
         }
         Contract.Assert(previouslySubmittedExchangeVisitor != null, "The previously submitted exchange visitor must not be null.");
         var count          = this.SEVISBatchCreateUpdateEV.UpdateEV == null ? 0 : this.SEVISBatchCreateUpdateEV.UpdateEV.Count();
         var addedItemCount = exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitor1Collection(sevisUsername, previouslySubmittedExchangeVisitor).Count();
         if (participant.SevisCommStatusId == SevisCommStatus.QueuedToValidate.Id)
         {
             addedItemCount += 1;
         }
         return(count + addedItemCount <= this.MaxUpdateExchangeVisitorRecordPerBatch);
     }
 }
        /// <summary>
        /// Adds the given exchange visitor to this batch.  If this batch can not be added an exception is thrown.
        /// </summary>
        /// <param name="exchangeVisitor">The exchange visitor to add.</param>
        public void AddExchangeVisitor(SevisGroupedParticipantDTO participant, ExchangeVisitor exchangeVisitor, ExchangeVisitor previouslySubmittedExchangeVisitor = null)
        {
            Contract.Requires(exchangeVisitor != null, "The exchange visitor must not be null.");
            Contract.Requires(exchangeVisitor.Person != null, "The exchange visitor person must not be null.");
            Contract.Requires(participant != null, "The participant must not be null.");
            Contract.Requires(participant.ParticipantId == exchangeVisitor.Person.ParticipantId, "The participant must belong to the exchange visitor.");

            var existingExchangeVisitor = this.exchangeVisitors.Where(x => x.Person.ParticipantId == exchangeVisitor.Person.ParticipantId).FirstOrDefault();

            if (existingExchangeVisitor != null)
            {
                return;
            }
            var message = "This StagedSevisBatch can not accomodate the given exchange visitor.";

            if (String.IsNullOrWhiteSpace(exchangeVisitor.SevisId))
            {
                var list = this.SEVISBatchCreateUpdateEV.CreateEV != null?this.SEVISBatchCreateUpdateEV.CreateEV.ToList() : new List <SEVISEVBatchTypeExchangeVisitor>();

                list.Add(exchangeVisitor.GetSEVISBatchTypeExchangeVisitor(this.SevisUsername));
                this.SEVISBatchCreateUpdateEV.CreateEV = list.ToArray();
                if (this.SEVISBatchCreateUpdateEV.CreateEV.Count() > this.MaxCreateExchangeVisitorRecordsPerBatch)
                {
                    throw new NotSupportedException(message);
                }
            }
            else
            {
                if (previouslySubmittedExchangeVisitor == null)
                {
                    throw new NotSupportedException("The previously submitted exchange visitor must be supplied, since the exchange visitor has a sevis id.");
                }
                Contract.Assert(previouslySubmittedExchangeVisitor != null, "The previously submitted exchange visitor must not be null.");
                var list = this.SEVISBatchCreateUpdateEV.UpdateEV != null?this.SEVISBatchCreateUpdateEV.UpdateEV.ToList() : new List <SEVISEVBatchTypeExchangeVisitor1>();

                if (participant.SevisCommStatusId == SevisCommStatus.QueuedToValidate.Id)
                {
                    list.Add(exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitorValidate(this.SevisUsername));
                }
                list.AddRange(exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitor1Collection(this.SevisUsername, previouslySubmittedExchangeVisitor));
                this.SEVISBatchCreateUpdateEV.UpdateEV = list.ToArray();
                if (this.SEVISBatchCreateUpdateEV.UpdateEV.Count() > this.MaxUpdateExchangeVisitorRecordPerBatch)
                {
                    throw new NotSupportedException(message);
                }
            }
            this.exchangeVisitors.Add(exchangeVisitor);
        }
        /// <summary>
        /// Runs a validation on sevis information for the participant with the given id and updates the sevis comm
        /// status with the latest validation result.  If the sevis validation is successful then a sevis comm status is added
        /// with the Ready To Submit status, otherwise, Information Required is set.
        /// </summary>
        /// <param name="user">The user performing the validation.</param>
        /// <param name="projectId">The project id of the participant.</param>
        /// <param name="participantId">The id of the participant.</param>
        /// <returns>The added participant sevis comm status.</returns>
        public async Task <ParticipantPersonSevisCommStatus> RunParticipantSevisValidationAsync(int projectId, int participantId)
        {
            var participant = await Context.Participants.FindAsync(participantId);

            throwIfModelDoesNotExist(participantId, participant, typeof(Participant));

            var participantPerson = await Context.ParticipantPersons.FindAsync(participantId);

            throwIfModelDoesNotExist(participantId, participantPerson, typeof(ParticipantPerson));

            if (ShouldRunValidation(participant, participantPerson))
            {
                var exchangeVisitor = await this.exchangeVisitorService.GetExchangeVisitorAsync(projectId, participantId);

                var hasChanges = String.IsNullOrWhiteSpace(exchangeVisitor.SevisId);
                if (!hasChanges)
                {
                    var history = await Context.ExchangeVisitorHistories.FindAsync(participantId);

                    if (history != null && history.LastSuccessfulModel != null)
                    {
                        var previouslySubmittedExchangeVisitor = ExchangeVisitor.GetExchangeVisitor(history.LastSuccessfulModel);
                        //either the previous exchange visitor has differences with the exchange visitor, or the previous exchange visitor
                        //does not have a sevis id i.e. it was just created and now we have a sevis id
                        hasChanges = exchangeVisitor.HasChanges(previouslySubmittedExchangeVisitor) || String.IsNullOrWhiteSpace(previouslySubmittedExchangeVisitor.SevisId);
                    }
                    else
                    {
                        hasChanges = true;
                    }
                }
                if (hasChanges)
                {
                    ValidationResult validationResult = exchangeVisitor.Validate(this.ExchangeVisitorValidator);
                    return(await HandleValidationResultAsync(exchangeVisitor, participantPerson, validationResult));
                }
                else
                {
                    HandleNonValidatedParticipant(participantPerson);
                    return(null);
                }
            }
            else
            {
                HandleNonValidatedParticipant(participantPerson);
                return(null);
            }
        }
        private ParticipantPersonSevisCommStatus HandleValidationResult(ExchangeVisitor exchangeVisitor, ParticipantPerson person, ValidationResult result)
        {
            //remember this method should be as performant as possible since lots of different entity edits can cause this method to run
            person.SevisValidationResult = GetSevisValidationResultAsJson(result);
            var latestCommStatus = CreateGetLatestParticipantPersonSevisCommStatusQuery(person.ParticipantId).FirstOrDefault();

            if (!result.IsValid)
            {
                if (!String.IsNullOrWhiteSpace(person.SevisId))
                {
                    var isParticipantReadyToValidate = this.participantPersonSevisService.IsParticipantReadyToValidate(person.ParticipantId);
                    if (isParticipantReadyToValidate)
                    {
                        return(AddOrUpdateParticipantPersonSevisCommStatus(latestCommStatus, person.ParticipantId, SevisCommStatus.NeedsValidationInfo.Id));
                    }

                    var hasParticipantNeededValidationInfo = CreateGetParticipantPersonSevisCommStatusBySevisCommStatusIdQuery(person.ParticipantId, SevisCommStatus.NeedsValidationInfo.Id).Count() > 0;
                    if (!exchangeVisitor.IsValidated && hasParticipantNeededValidationInfo)
                    {
                        return(AddOrUpdateParticipantPersonSevisCommStatus(latestCommStatus, person.ParticipantId, SevisCommStatus.NeedsValidationInfo.Id));
                    }

                    return(AddOrUpdateParticipantPersonSevisCommStatus(latestCommStatus, person.ParticipantId, SevisCommStatus.InformationRequired.Id));
                }
                else
                {
                    return(AddOrUpdateParticipantPersonSevisCommStatus(latestCommStatus, person.ParticipantId, SevisCommStatus.InformationRequired.Id));
                }
            }
            else
            {
                var hasParticipantNeededValidationInfo = CreateGetParticipantPersonSevisCommStatusBySevisCommStatusIdQuery(person.ParticipantId, SevisCommStatus.NeedsValidationInfo.Id).Count() > 0;
                var isParticipantReadyToValidate       = this.participantPersonSevisService.IsParticipantReadyToValidate(person.ParticipantId);
                if ((hasParticipantNeededValidationInfo && !exchangeVisitor.IsValidated) || isParticipantReadyToValidate)
                {
                    return(AddParticipantPersonSevisCommStatus(person.ParticipantId, SevisCommStatus.ReadyToValidate.Id));
                }
                else
                {
                    return(AddParticipantPersonSevisCommStatus(person.ParticipantId, SevisCommStatus.ReadyToSubmit.Id));
                }
            }
        }
Example #6
0
        public ExchangeVisitor GetExchangeVisitor(string sevisId, int personId, int participantId)
        {
            var state       = "TN";
            var mailAddress = new AddressDTO();

            mailAddress.Country     = LocationServiceAddressValidator.UNITED_STATES_COUNTRY_NAME;
            mailAddress.DivisionIso = state;
            mailAddress.Street1     = "123 Us address";
            mailAddress.Street2     = null;
            mailAddress.City        = "city";
            mailAddress.PostalCode  = "55555";

            var usAddress = new AddressDTO();

            usAddress.Country     = LocationServiceAddressValidator.UNITED_STATES_COUNTRY_NAME;
            usAddress.DivisionIso = state;
            usAddress.Street1     = "123 Us address";
            usAddress.Street2     = null;
            usAddress.City        = "city";
            usAddress.PostalCode  = "55555";

            var firstName = "first";
            var lastName  = "last";
            var passport  = "passport";
            var preferred = "preferred";
            var suffix    = "Jr.";
            var fullName  = new FullName(firstName, lastName, passport, preferred, suffix);

            var   birthCity              = " birth city";
            var   birthCountryCode       = "US";
            var   birthDate              = DateTime.UtcNow;
            var   citizenshipCountryCode = "FR";
            var   email  = "*****@*****.**";
            var   gender = Gender.SEVIS_MALE_GENDER_CODE_VALUE;
            var   permanentResidenceCountryCode = "MX";
            var   phone                = "8505551212";
            short positionCode         = 120;
            var   printForm            = true;
            var   remarks              = "remarks";
            var   programCataegoryCode = "1D";

            var subjectFieldCode = "01.0102";
            var subjectField     = new SubjectField(subjectFieldCode, null, null, "remarks");

            var sevisOrgId = "abcde12347890";

            var person = new Business.Validation.Sevis.Bio.Person(
                fullName,
                birthCity,
                birthCountryCode,
                birthDate,
                citizenshipCountryCode,
                email,
                gender,
                permanentResidenceCountryCode,
                phone,
                remarks,
                positionCode.ToString(),
                programCataegoryCode,
                subjectField,
                mailAddress,
                usAddress,
                printForm,
                personId,
                participantId);
            var siteOfActivity = new AddressDTO
            {
                Street1      = "street 1",
                PostalCode   = "12345",
                DivisionIso  = "DC",
                LocationName = "US Dept of State"
            };
            var exchangeVisitor = new ExchangeVisitor(
                sevisId: sevisId,
                sevisOrgId: sevisOrgId,
                isValidated: false,
                person: person,
                financialInfo: new Business.Validation.Sevis.Finance.FinancialInfo(true, true, null, null),
                occupationCategoryCode: "99",
                programEndDate: DateTime.Now,
                programStartDate: DateTime.Now,
                dependents: new List <Business.Validation.Sevis.Bio.Dependent>(),
                siteOfActivity: siteOfActivity);

            return(exchangeVisitor);
        }