public IActionResult Post([FromBody] ViewModels.ParticipantViewModel Participantvalues)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CertifiedVals = ScoreValLogic.Certify(Participantvalues);
            GeoLocProps GetGeoLocation = getGeoLocations().Result;
            string      Address        = string.Format("{0} {1} {2}", Participantvalues.City, " , ", Participantvalues.State);
            MapPoint    mapCords       = latlangofAddr(Address, GetGeoLocation.Latitude, GetGeoLocation.Longitude);
            bool        ZipCordsMatch  = VerifyZipCords(GetGeoLocation.ZipCode, Participantvalues.Zip);

            scoremodel = CalculateScore.CalscoreVal(CertifiedVals, mapCords, ZipCordsMatch);
            UserAgent.UserAgent ua = BrowserLookup();



            storetoDB(Participantvalues, scoremodel, GetGeoLocation, ua, mapCords);
            return(Ok());
        }
Example #2
0
        public static ScoreModel Certify(ViewModels.ParticipantViewModel Participantvalues)
        {
            ScoreModel score = new ScoreModel();

            score.FirstName_Match = String.Equals(FB_first_name, Participantvalues.FirstName, StringComparison.OrdinalIgnoreCase) ? true : false;
            score.LastName_Match  = String.Equals(FB_last_name, Participantvalues.LastName, StringComparison.OrdinalIgnoreCase) ? true : false;
            score.Gender_Match    = String.Equals(FB_gender, Participantvalues.GenderIdentity, StringComparison.OrdinalIgnoreCase) ? true : false;
            score.Verified        = String.Equals(FB_verified, "true", StringComparison.OrdinalIgnoreCase) ? true : false;



            //==========================================================================
            //Cross Checking Age
            //==========================================================================
            int DOB      = Participantvalues.YearofBirth;
            int calAge   = DateTime.Now.Year - DOB;
            int givenAge = Int32.Parse(Participantvalues.Age);

            if (calAge == givenAge || calAge == givenAge + 1 || calAge == givenAge - 1)
            {
                score.AgeValid = true;
            }
            else
            {
                score.AgeValid = false;
            }
            //==========================================================================
            //Cross Checking Location
            //==========================================================================

            int            zipcode = Int32.Parse(Participantvalues.Zip);
            Task <Address> task    = CityStarefromZipService.VerifyAddress(zipcode);
            Address        addr    = task.Result;

            score.StateValid = String.Equals(addr.state, Participantvalues.State, StringComparison.OrdinalIgnoreCase) ? true : false;
            score.CityValid  = String.Equals(addr.city, Participantvalues.City, StringComparison.OrdinalIgnoreCase) ? true : false;
            return(score);
        }
        //-------------------------------------------------------------------------------------------------------------------------



        //--------------------------------------------------------------------------------------------------------------------------

        public void storetoDB(ViewModels.ParticipantViewModel Participantvalues, ScoreModel score, GeoLocProps geo, UserAgent.UserAgent useragent, MapPoint mapCoords)
        {
            ParticipantDBViewModel dbModel = CertifyParticipant.storingtoDB(Participantvalues, score, geo, useragent, mapCoords);

            Participant participant = Mapper.Map <Participant>(dbModel);


            SurveyOptionsDBModel surveymodel = CalculateScore.getthesurveyObject();

            DAL.Models.Survey surveydal = new DAL.Models.Survey();
            //defining the survey object
            surveydal.Survey_Name       = surveymodel.Survey_Name;
            surveydal.Survey_Active     = surveymodel.Survey_Active;
            surveydal.SurveyId          = surveymodel.SurveyId;
            surveydal.CalAddressScore   = surveymodel.CalAddressScore;
            surveydal.CalAgeScore       = surveymodel.CalAgeScore;
            surveydal.CalSocialScore    = surveymodel.CalSocialScore;
            surveydal.CalTwoFactorScore = surveymodel.CalTwoFactorScore;

            _unitOfWork.ParticipantRepository.InsertSurveyParticipant(participant);

            _unitOfWork.ParticipantRepository.InsertSurveyParticipantTable(participant, surveydal);
        }