Exemple #1
0
        public bool SaveSurvey(List <SurveyTakenModel> lst, SurveyCompledModel _model)
        {
            bool flag = false;

            try
            {
                using (LBCData context = new LBCData(ConnectionHelper.getConnectionString()))
                {
                    foreach (var item in lst)
                    {
                        LBC_SURVEY_TAKEN _survey = new LBC_SURVEY_TAKEN()
                        {
                            STARS_ID     = item.STARS_ID,
                            SURVEY_ID    = item.SURVEY_ID,
                            QUESTION_ID  = item.QUESTION_ID,
                            ANSWER_ID    = item.ANSWER_ID,
                            ANSWER_MSG   = item.ANSWER_MSG,
                            CREATED_BY   = item.CREATED_BY,
                            CREATED_DATE = DateTime.Now
                        };
                        context.LBC_SURVEY_TAKEN.Add(_survey);
                    }
                    LBC_SURVERY_COMPLETED _survey_completed = new LBC_SURVERY_COMPLETED()
                    {
                        COMPLETED_DATE = DateTime.Now,
                        SURVEY_ID      = _model.SURVEY_ID,
                        STARS_ID       = _model.STARS_ID,
                        PA_CODE        = _model.PA_CODE,
                        CREATED_DATE   = _model.CREATED_DATE,
                        CREATED_BY     = _model.CREATED_BY
                    };

                    context.LBC_SURVERY_COMPLETED.Add(_survey_completed);

                    context.SaveChanges();
                    flag = true;
                }
            }

            catch (Exception ex)
            {
                flag = false;
            }

            return(flag);
        }
        //public List<SurveyQuestionModel> GetReportQuestions()
        //{
        //    SurveyRepository _survey = new SurveyRepository();
        //    return _survey.GetReportQuestions();
        //}
        public bool SaveSurvey(List <SurveyTakenModel> lst, SurveyCompledModel _model)
        {
            SurveyRepository _survey = new SurveyRepository();

            return(_survey.SaveSurvey(lst, _model));
        }
Exemple #3
0
        public ActionResult Survey(FormCollection frm)
        {
            SurveyBL _surBL = new SurveyBL();

            decimal surveyId = 1; // Make sure you get the Survey Id from the table or session
            List <SurveyQuestionModel> lstQuestions = _surBL.getQuestions(surveyId);

            List <SurveyTakenModel> lst = new List <SurveyTakenModel>();


            var starsId = Session["StarsIdProfile"].ToString();
            var pacode  = Session["w_pacode"].ToString();
            var wslx    = Session["w_user"].ToString();


            for (int i = 0; i <= frm.Count - 1; i++)
            {
                string type = "";
                //string test1 = frm.GetValue(Convert.ToString(frm[i])).AttemptedValue;
                // string[] arr1 = frm.GetValues(i);
                foreach (var item in lstQuestions)
                {
                    if (item.QUESTION_ID == Convert.ToDecimal(frm.GetKey(i)))
                    {
                        type = item.QUESTION_TYPE;
                        break;
                    }
                }
                if (type == "FI")
                {
                    string[] arr = frm.GetValue(Convert.ToString(frm.GetKey(i))).AttemptedValue.Split(',');
                    lst.Add(new SurveyTakenModel()
                    {
                        STARS_ID    = starsId,
                        SURVEY_ID   = surveyId,
                        QUESTION_ID = Convert.ToDecimal(frm.GetKey(i).ToString()),
                        ANSWER_ID   = 1,
                        ANSWER_MSG  = arr[0].ToString(),
                        CREATED_BY  = wslx
                    });
                }
                else if (type == "MS")
                {
                    string[] arr = frm.GetValue(Convert.ToString(frm.GetKey(i))).AttemptedValue.Split(',');
                    if (arr.Count() > 0)
                    {
                        for (int j = 0; j <= arr.Count() - 1; j = j + 2)
                        {
                            lst.Add(new SurveyTakenModel()
                            {
                                STARS_ID    = starsId,
                                SURVEY_ID   = surveyId,
                                QUESTION_ID = Convert.ToDecimal(arr[j].ToString()),
                                ANSWER_ID   = Convert.ToDecimal(arr[j + 1].ToString()),
                                ANSWER_MSG  = string.Empty,
                                CREATED_BY  = wslx
                            });
                        }
                    }
                }

                else
                {
                    string[] arr = frm.GetValue(Convert.ToString(frm.GetKey(i))).AttemptedValue.Split(',');

                    lst.Add(new SurveyTakenModel()
                    {
                        STARS_ID    = starsId,
                        SURVEY_ID   = surveyId,
                        QUESTION_ID = Convert.ToDecimal(arr[0].ToString()),
                        ANSWER_ID   = Convert.ToDecimal(arr[1].ToString()),
                        ANSWER_MSG  = string.Empty,
                        CREATED_BY  = wslx
                    });
                }
            }
            SurveyCompledModel _surveyModel = new SurveyCompledModel();

            _surveyModel.COMPLETED_DATE = DateTime.Now;
            _surveyModel.PA_CODE        = pacode;
            _surveyModel.STARS_ID       = starsId;
            _surveyModel.SURVEY_ID      = surveyId;
            _surveyModel.CREATED_DATE   = DateTime.Now;
            _surveyModel.CREATED_BY     = wslx;

            if (_surBL.SaveSurvey(lst, _surveyModel))
            {
                return(RedirectToAction("Confirmation", "Resources"));
            }
            return(RedirectToAction("Survey", "Resources"));
            //return RedirectToAction("Welcome", "LBC");
        }