Example #1
0
        internal async Task <ResponseModel> SaveScreenQuestion(ScreenQuestion source, int loginId)
        {
            ResponseModel response = new ResponseModel();

            using (IDbConnection conn = _dbConnection.Connection)
            {
                List <XElement>   toAdd = new List <XElement>();
                DynamicParameters param = new DynamicParameters();

                if (source.questionid > 0)
                {
                    param.Add("@Id", source.questionid, DbType.Int32);
                }
                if (source.parentquestionid.HasValue && source.parentquestionid > 0)
                {
                    param.Add("@ParentQuestionId", source.parentquestionid, DbType.Int32);
                }
                if (source.hint.Trim().Length > 0)
                {
                    param.Add("@Hint", source.hint, DbType.String);
                }

                param.Add("@QuestionNumber", source.questionnumber.Trim(), DbType.String);
                param.Add("@Question", source.question.Trim(), DbType.String);
                param.Add("@QuestionType", source.questiontype.Trim(), DbType.String);
                param.Add("@ShowNA", source.showNA, DbType.Boolean);
                param.Add("@IsMandatory", source.ismandatory, DbType.Boolean);
                param.Add("@IsParent", source.isparent, DbType.Boolean);
                param.Add("@LoginUserId", loginId, DbType.Int32);

                var data = await conn.QueryAsync <int>(Constants.StoredProcedure.MANAGESCREENQUESTION, param, null, null, CommandType.StoredProcedure);

                int result = 0;

                if (data.ToList().Count > 0)
                {
                    result = data.ToList()[0];
                }

                if (source.options != null && source.options.Count > 0 && result > 0)
                {
                    source.options.ForEach((x) =>
                    {
                        toAdd.Add(new XElement("Option", new XAttribute("SequenceOrder", toAdd.Count + 1)
                                               , new XAttribute("ScreenQuestionId", result)
                                               , new XAttribute("Option", x.option ?? string.Empty)
                                               , new XAttribute("OptionAction", x.optionaction == null || x.optionaction == "0" ? string.Empty : x.optionaction)
                                               , new XAttribute("IsNA", x.isNA)
                                               , new XAttribute("LoginId", loginId)));
                    });

                    if (toAdd.Count() > 0)
                    {
                        var add = new XElement("Options", toAdd);

                        DynamicParameters param2 = new DynamicParameters();
                        param2.Add("@XMLOptions", add.ToString(), DbType.String);
                        param2.Add("@QuestionId", result, DbType.String);

                        var data2 = await conn.QueryAsync <int>(Constants.StoredProcedure.MANAGESCREENOPTION, param2, null, null, CommandType.StoredProcedure);

                        int result2 = 0;

                        if (data2.ToList().Count > 0)
                        {
                            result2 = data2.ToList()[0];
                        }

                        if (result2 <= 0)
                        {
                            response.ResultStatus   = result2;
                            response.SuccessMessage = result2 <= 0 ? string.Empty : "Screening Question saved successfully.";
                            response.ErrorMessage   = result2 <= 0 ? "Error occurred while saving screening question option.  Please try again." : string.Empty;
                            return(response);
                        }
                    }
                }

                response.ResultStatus   = result >= 1 ? 1 : result;
                response.SuccessMessage = result <= 0 ? string.Empty : "Screening Question saved successfully.";
                response.ErrorMessage   = result <= 0 ? "Error occurred while saving screening question.  Please try again." : string.Empty;
            }

            return(response);
        }
Example #2
0
        public async Task <HttpResponseMessage> SaveScreenQuestion(ScreenQuestion source)
        {
            ResponseModel result = await VisaDal.Instance.SaveScreenQuestion(source, source.loginid);

            return(sendResult(result));
        }