/// <summary>
        /// Get Document response detail
        /// </summary>
        /// <param name="objDocumentDetailModel">object of DocumentResponseDetailModel</param>
        /// <param name="IsSave">if true then Fetch record for Save else for View.</param>
        public DocumentResponseDetailModel GetDocumentResponse(DocumentResponseDetailModel objDocumentDetailModel, bool IsSave)
        {
            if (IsSave)
            {
                serviceResponse        = objUtilityWeb.PostAsJsonAsync(WebApiURL.DocumentResponse + "/GetDocumentResponseForSave", objDocumentDetailModel);
                objDocumentDetailModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <DocumentResponseDetailModel>().Result : null;

                //objDocumentDetailModel = objBLDocumentResponse.GetDocumentResponseForSave(objDocumentDetailModel);
            }
            else
            {
                serviceResponse        = objUtilityWeb.PostAsJsonAsync(WebApiURL.DocumentResponse + "/GetDocumentResponseForView", objDocumentDetailModel);
                objDocumentDetailModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <DocumentResponseDetailModel>().Result : null;

                //objDocumentDetailModel = objBLDocumentResponse.GetDocumentResponseForView(objDocumentDetailModel);
            }
            if (objDocumentDetailModel != null && objDocumentDetailModel.Questions != null && objDocumentDetailModel.Questions.Count() > 0)
            {
                CommonUtils objCommonUtils = new CommonUtils();
                //set question type property
                foreach (ViewQuestionAnswerModel objViewQuestionAnswerModel in objDocumentDetailModel.Questions)
                {
                    objViewQuestionAnswerModel.QuestionTypeDetail = new QuestionTypeDetailModel();
                    if (!String.IsNullOrEmpty(objViewQuestionAnswerModel.QuestionType))
                    {
                        objViewQuestionAnswerModel.QuestionTypeDetail = objCommonUtils.SetQuestionProperties(objViewQuestionAnswerModel.QuestionType, objViewQuestionAnswerModel.QuestionPropertyList, objViewQuestionAnswerModel.QuestionTypeDetail, objViewQuestionAnswerModel.QuestionOptionsList);
                    }
                }
            }

            return(objDocumentDetailModel);
        }
 /// <summary>
 /// Insert or Update Document Answer
 /// </summary>
 /// <param name="objViewQuestionModel">Object of Model ViewQuestionModel</param>
 /// <returns></returns>
 public DocumentResponseDetailModel InsertUpdateDocumentResult(DocumentResponseDetailModel objDocumentResponseDetailModel)
 {
     try
     {
         DLDocumentResponse objDLDocumentResponse = new DLDocumentResponse();
         //call InsertUpdateDocumentQuestion Method of dataLayer and return DocumentResponseDetailModel
         return(objDLDocumentResponse.InsertUpdateDocumentResult(objDocumentResponseDetailModel));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public DocumentResponseDetailModel GetDocumentResponseForSave(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            BLDocument objBLDocument = new BLDocument();
            BLStep     objBLStep     = new BLStep();

            //1. Fill Document detail
            objDocumentResponseDetailModel.objDocumentModel = new DocumentModel();
            objDocumentResponseDetailModel.objDocumentModel = objBLDocument.GetDocumentById(objDocumentResponseDetailModel.DocumentID);
            objDocumentResponseDetailModel.objDocumentModel.DocumentHTML = objBLDocumentResponse.GetDocumentPreviewTemp(objDocumentResponseDetailModel.DocumentID, objDocumentResponseDetailModel.UserId);
            //2. Fill Step detail
            objDocumentResponseDetailModel.objStepList = new List <StepModel>();
            objDocumentResponseDetailModel.objStepList = objBLStep.GetStepByDocumentIdAndUserId(objDocumentResponseDetailModel.DocumentID, objDocumentResponseDetailModel.UserId);


            return(objBLDocumentResponse.GetDocumentResponseForSave(objDocumentResponseDetailModel));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get Document response detail
        /// </summary>
        /// <param name="UserSessionModel"></param>
        /// <returns>Object of DataTable</returns>
        public DataSet GetDocumentResponseForSave(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            try
            {
                //create error code and error message output parameter.
                int          ErrorCode  = 0;
                SqlParameter pErrorCode = new SqlParameter("@ErrorCode", ErrorCode);
                pErrorCode.Direction = ParameterDirection.Output;
                SqlParameter pErrorMessage = new SqlParameter("@ErrorMessage", SqlDbType.NVarChar, 100);

                pErrorMessage.Direction = ParameterDirection.Output;



                //Set Param values by objViewParameters
                SqlParameter[] Param =
                {
                    new SqlParameter("@DocumentID",        objDocumentResponseDetailModel.DocumentID),
                    new SqlParameter("@UserId",            objDocumentResponseDetailModel.UserId),
                    new SqlParameter("@ApplicationRoleID", objDocumentResponseDetailModel.ApplicationRoleID),
                    new SqlParameter("@CurrentPage",       objDocumentResponseDetailModel.CurrentPage),
                    new SqlParameter("@PageSize",          objDocumentResponseDetailModel.PageSize),
                    new SqlParameter("@FolderId",          objDocumentResponseDetailModel.FolderId),
                    new SqlParameter("@IsSave",            objDocumentResponseDetailModel.isSaved),
                    new SqlParameter("@MaxPage",           objDocumentResponseDetailModel.MaxPage)
                    ,                                      pErrorCode
                    ,                                      pErrorMessage
                };

                //Call spGetDocumentResponse for Save Procedure
                DataSet dt = SQLHelper.ExecuteDataset(SQLHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, DBConstants.Web_GetDocumentResponseForSaveStep, Param);
                //set Error code into model
                objDocumentResponseDetailModel.ErrorCode = Convert.ToInt32(pErrorCode.Value);
                objDocumentResponseDetailModel.Message   = Convert.ToString(pErrorMessage.Value);
                if (dt != null)
                {
                    return(dt);
                }

                return(null);
            }
            catch (Exception ex)
            {
                //throw exception.
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public static MvcHtmlString AnswerRadioButtonFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, ViewQuestionAnswerModel objQuestionAnswerModel, QuestionOptionsModel objQuestionOption, int optionIndex)
        {
            MvcHtmlString html          = default(MvcHtmlString);
            string        strHtml       = "";
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);

            var properties = typeof(SingleSelectModel).GetProperties();

            if (objQuestionAnswerModel != null && objQuestionAnswerModel.QuestionOptionsList != null)
            {
                object model = htmlHelper.ViewData.Model;
                DocumentResponseDetailModel objModel = (DocumentResponseDetailModel)model;
                //for (int i = 0; i < objQuestionTypeModel.lstSingleSelection.Count(); i++)
                //{
                var Attributes = GetAttributes(objQuestionAnswerModel);

                Attributes["class"] += "radioanswer";
                Attributes.Add("id", "rdb_" + objModel.Questions[objModel.Index].QuestionOptionsList[optionIndex].QuestionOptionsID + "_" + objModel.Questions[objModel.Index].QuestionID);
                Attributes.Add("Value", objModel.Questions[objModel.Index].QuestionOptionsList[optionIndex].QuestionOptionsID);

                html = System.Web.Mvc.Html.InputExtensions.RadioButton(htmlHelper, "questionAnswer_" + objModel.Questions[objModel.Index].QuestionID,
                                                                       objModel.Questions[objModel.Index].QuestionOptionsList[optionIndex].QuestionOptionsID, Attributes);
                //html = System.Web.Mvc.Html.InputExtensions.RadioButton(htmlHelper, "questionAnswer_" + objModel.Questions[objModel.Index].QuestionID,
                //    objModel.Questions[objModel.Index].QuestionOptionsList[optionIndex].QuestionOptionsID,
                //    new
                //    {
                //        @class = "radioanswer",
                //        id = "rdb_" + objModel.Questions[objModel.Index].QuestionOptionsList[optionIndex].QuestionOptionsID + "_" + objModel.Questions[objModel.Index].QuestionID,
                //        Value = objModel.Questions[objModel.Index].QuestionOptionsList[optionIndex].QuestionOptionsID
                //    });
                //html = System.Web.Mvc.Html.InputExtensions.RadioButton(htmlHelper, "rbSingle", objQuestionOption.OptionText, false, Attributes);
                strHtml += html.ToHtmlString();
                html     = System.Web.Mvc.Html.InputExtensions.HiddenFor(htmlHelper, expression);
                strHtml += html.ToHtmlString();
                strHtml += "<label>" + objQuestionOption.OptionText + "</label>";

                strHtml += GetStringFromModel(objQuestionAnswerModel.QuestionTypeDetail.SingleSelect, properties, htmlFieldName);
                // }
            }
            else
            {
                html    = System.Web.Mvc.Html.InputExtensions.RadioButtonFor(htmlHelper, expression, "");
                strHtml = html.ToHtmlString();
            }
            return(new MvcHtmlString(strHtml));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Document response detail for view
        /// </summary>
        /// <param name="UserSessionModel"></param>
        /// <returns>Object of DataTable</returns>
        public DataTable GetDocumentResponseForView(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            try
            {
                //create error code and error message paramtere for sql procedure
                int          ErrorCode  = 0;
                SqlParameter pErrorCode = new SqlParameter("@ErrorCode", ErrorCode);
                pErrorCode.Direction = ParameterDirection.Output;
                SqlParameter pErrorMessage = new SqlParameter("@ErrorMessage", SqlDbType.NVarChar, 100);

                pErrorMessage.Direction = ParameterDirection.Output;



                //Set Param values by objViewParameters
                SqlParameter[] Param =
                {
                    new SqlParameter("@DocumentID",        objDocumentResponseDetailModel.DocumentID),
                    new SqlParameter("@UserId",            objDocumentResponseDetailModel.UserId),
                    new SqlParameter("@ApplicationRoleID", objDocumentResponseDetailModel.ApplicationRoleID),
                    new SqlParameter("@NoOfAttempt",       objDocumentResponseDetailModel.NoOfAttempt),
                    new SqlParameter("@CurrentPage",       objDocumentResponseDetailModel.CurrentPage),
                    new SqlParameter("@PageSize",          objDocumentResponseDetailModel.PageSize)
                    ,                                      pErrorCode
                    ,                                      pErrorMessage
                };

                //Call spGetDocumentResponse Procedure for view
                DataTable dt = SQLHelper.ExecuteDataTable(SQLHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, DBConstants.Web_GETDocumentRESPONSEFORVIEW, Param);
                //Set error code into Model
                objDocumentResponseDetailModel.ErrorCode = Convert.ToInt32(pErrorCode.Value);
                objDocumentResponseDetailModel.Message   = Convert.ToString(pErrorMessage.Value);
                if (dt != null)
                {
                    return(dt);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //[Filters.Authorized]
        public ActionResult ViewDocumentResponse(DocumentResponseDetailModel objDocumentDetailModel)
        {
            try
            {
                //check no of attempt change on view page then set current page to 1
                if (objDocumentDetailModel != null && !string.IsNullOrWhiteSpace(objDocumentDetailModel.ActionType) && objDocumentDetailModel.ActionType == "changeattempt")
                {
                    objDocumentDetailModel.CurrentPage = 1;
                }

                //Get Document response detail model from database.
                //Set false for view Document
                GetDocumentResponse(objDocumentDetailModel, false);
            }
            //if there is any error exception then set error message and log detail of error into database.
            catch (Exception ex)
            {
                ErrorLog(ex, "DocumentResponse", "ViewDocumentResponse Post");
                //objDocumentDetailModel.Message = String.Format(DocumentResponse.msgViewDocumentError, "View Document Response");
                objDocumentDetailModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
            }
            return(PartialView("_ViewDocumentQueAnsList", objDocumentDetailModel));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Insert or Update Document Question answer detail
        /// </summary>
        /// <param name="objDocumentResponseDetailModel"></param>
        /// <returns></returns>
        public DocumentResponseDetailModel InsertUpdateDocumentResult(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            try
            {
                //Create error code and error message into sql proc
                int          ErrorCode    = 0;
                string       ErrorMessage = "";
                SqlParameter pErrorCode   = new SqlParameter("@ErrorCode", ErrorCode);
                pErrorCode.Direction = ParameterDirection.Output;
                SqlParameter pErrorMessage = new SqlParameter("@ErrorMessage", ErrorMessage);
                pErrorMessage.Direction = ParameterDirection.Output;

                SqlParameter[] parmList =
                {
                    new SqlParameter("@DocumentResultID", objDocumentResponseDetailModel.Result.DocumentResultID)
                    ,                                     new SqlParameter("@DocumentTargetAudienceID", objDocumentResponseDetailModel.Result.DocumentTargetAudienceID)
                    ,                                     new SqlParameter("@NoOfAttempt", objDocumentResponseDetailModel.Result.NoOfAttempt)
                    ,                                     new SqlParameter("@IsCompleted", objDocumentResponseDetailModel.Result.IsCompleted)
                    ,                                     new SqlParameter("@CreatedBy", objDocumentResponseDetailModel.CommonCreatedBy)
                    ,                                     new SqlParameter("@QuestionAnswerXml", objDocumentResponseDetailModel.QuestionAnswerXml)
                    ,                                     pErrorCode
                    ,                                     pErrorMessage
                };

                //Exucute sql insertion/updation procedure for sql Document result detail.
                SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, DBConstants.Web_INSERTUPDATEDocumentRESPONSE, parmList);
                //set error code and message
                objDocumentResponseDetailModel.ErrorCode = Convert.ToInt32(pErrorCode.Value);
                objDocumentResponseDetailModel.Message   = Convert.ToString(pErrorMessage.Value);
                return(objDocumentResponseDetailModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //[Filters.MenuAccess]
        public ActionResult ViewDocumentPreview(string prm)
        {
            //Object of Model.
            DocumentResponseDetailModel objDocumentDetailModel = new DocumentResponseDetailModel();

            try
            {
                int    DocumentID = 0;
                String PageName   = string.Empty;
                if (!String.IsNullOrEmpty(prm))
                {
                    //Decrypt query string
                    string inputParameter = CommonUtils.Decrypt(prm).ToString().Replace("?", "").ToLower();

                    //Get query string paramtere  and set value
                    // get Document id
                    if (inputParameter.IndexOf("Documentid") > -1)
                    {
                        foreach (var item in inputParameter.Split('&'))
                        {
                            if (item.IndexOf("Documentid") > -1)
                            {
                                int.TryParse(item.Replace("Documentid=", ""), out DocumentID);
                            }
                            // get page name where from this page url is open.
                            if (item.IndexOf("pagename") > -1)
                            {
                                PageName = Convert.ToString(item.Replace("pagename=", ""));
                            }
                        }
                    }
                }

                //check page name is null or blank then set by default url.
                if (string.IsNullOrWhiteSpace(PageName))
                {
                    objDocumentDetailModel.ReferralUrl = "/Document/ViewDocument";
                    //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewDocument;//"View Document";
                }
                else if (string.IsNullOrWhiteSpace(objDocumentDetailModel.ReferralUrl))
                {
                    switch (PageName)
                    {
                    case "home":
                        objDocumentDetailModel.ReferralUrl = "/Home/Home";
                        objDocumentDetailModel.UrlTitle    = "Home";

                        break;

                    case "Documentuser":
                        objDocumentDetailModel.ReferralUrl = "/Document/viewDocumentuser?prm=" + CommonUtils.Encrypt(Convert.ToString(DocumentID));
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewDocumentUser;//"View Document User";
                        break;

                    default:
                        objDocumentDetailModel.ReferralUrl = "/Document/ViewDocument";
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewDocument;//"View Document";
                        break;
                    }
                }

                //Set default parameter
                objDocumentDetailModel.DocumentID = DocumentID;
                objDocumentDetailModel.IsReadOnly = false;
                //Get Document response detail model from database.

                serviceResponse        = objUtilityWeb.PostAsJsonAsync(WebApiURL.DocumentResponse + "/GetDocumentPreview", objDocumentDetailModel);
                objDocumentDetailModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <DocumentResponseDetailModel>().Result : null;

                //objDocumentDetailModel = objBLDocumentResponse.GetDocumentPreview(objDocumentDetailModel);

                switch (objDocumentDetailModel.ErrorCode)
                {
                case 61:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResource.msgDocumentNotExist;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));
                }
                if (objDocumentDetailModel != null && objDocumentDetailModel.Questions != null && objDocumentDetailModel.Questions.Count() > 0)
                {
                    CommonUtils objCommonUtils = new CommonUtils();
                    //set question type detail for questions
                    foreach (ViewQuestionAnswerModel objViewQuestionAnswerModel in objDocumentDetailModel.Questions)
                    {
                        objViewQuestionAnswerModel.QuestionTypeDetail = new QuestionTypeDetailModel();
                        if (!String.IsNullOrEmpty(objViewQuestionAnswerModel.QuestionType))
                        {
                            objViewQuestionAnswerModel.QuestionTypeDetail = objCommonUtils.SetQuestionProperties(objViewQuestionAnswerModel.QuestionType, objViewQuestionAnswerModel.QuestionPropertyList, objViewQuestionAnswerModel.QuestionTypeDetail, objViewQuestionAnswerModel.QuestionOptionsList);
                        }
                    }
                }
            }
            //handle exception and set error message and log.
            catch (Exception ex)
            {
                ErrorLog(ex, "DocumentResponse", "ViewDocumentPreview GET");
                //objDocumentDetailModel.Message = String.Format(DocumentResponse.msgViewDocumentError, "View Document Preview");
                objDocumentDetailModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
            }
            //return view
            return(View(objDocumentDetailModel));
        }
 /// <summary>
 /// Insert or Update Document Answer
 /// </summary>
 /// <param name="objViewQuestionModel">Object of Model ViewQuestionModel</param>
 /// <returns></returns>
 public DocumentResponseDetailModel InsertUpdateDocumentResult(DocumentResponseDetailModel objDocumentResponseDetailModel)
 {
     return(objBLDocumentResponse.InsertUpdateDocumentResult(objDocumentResponseDetailModel));
 }
 /// <summary>
 /// Get Document response detail
 /// </summary>
 /// <param name="ObjDocumentApplicationMappingDetail"></param>
 /// <returns></returns>
 public DocumentResponseDetailModel GetDocumentPreview(DocumentResponseDetailModel objDocumentResponseDetailModel)
 {
     return(objBLDocumentResponse.GetDocumentPreview(objDocumentResponseDetailModel));
 }
        /// <summary>
        /// Get  Document Response For Save
        /// </summary>
        /// <param name="ObjDocumentApplicationMappingDetail"></param>
        /// <returns></returns>
        public DocumentResponseDetailModel GetDocumentResponseForSave(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            DLDocumentResponse objDLDocumentResponse = new DLDocumentResponse();
            //Get Document detail into datatable
            DataSet dtDocument = objDLDocumentResponse.GetDocumentResponseForSave(objDocumentResponseDetailModel);

            if (dtDocument != null && dtDocument.Tables.Count > 0 && dtDocument.Tables[0].Rows.Count > 0)
            {
                int totalRecord = Convert.ToInt32(dtDocument.Tables[0].Rows[0]["TotalCount"]);
                //calculating total paging
                objDocumentResponseDetailModel.TotalPages = TotalPage(totalRecord, 1);
                objDocumentResponseDetailModel.MaxPage    = Convert.ToInt32(dtDocument.Tables[0].Rows[0]["MaxPage"]);
            }
            if (dtDocument != null && dtDocument.Tables.Count > 1 && dtDocument.Tables[1].Rows.Count > 0)
            {
                if (objDocumentResponseDetailModel != null)
                {
                    //2. fill Document question details
                    objDocumentResponseDetailModel.Questions = new List <ViewQuestionAnswerModel>();

                    for (int i = 0; i < dtDocument.Tables[1].Rows.Count; i++)
                    {
                        ViewQuestionAnswerModel objQuestionModel = new ViewQuestionAnswerModel();
                        //get question from list
                        objQuestionModel = GetDataRowToEntity <ViewQuestionAnswerModel>(dtDocument.Tables[1].Rows[i]);

                        if (objQuestionModel != null && !objDocumentResponseDetailModel.Questions.Any(a => a.QuestionID == objQuestionModel.QuestionID))
                        {
                            DataView ViewQuestion = new DataView(dtDocument.Tables[1]);
                            //filter Document question into Data view by question id.
                            ViewQuestion.RowFilter = "QuestionID=" + objQuestionModel.QuestionID;
                            DataTable dtFilter = ViewQuestion.ToTable();
                            objQuestionModel.QuestionOptionsList  = new List <QuestionOptionsModel>();
                            objQuestionModel.QuestionPropertyList = new List <QuestionPropertyModel>();
                            for (int j = 0; j < dtFilter.Rows.Count; j++)
                            {
                                //fill question option detail

                                QuestionOptionsModel objQuestionOptionModel = new QuestionOptionsModel();
                                objQuestionOptionModel = GetDataRowToEntity <QuestionOptionsModel>(dtFilter.Rows[j]);
                                if (objQuestionOptionModel != null && objQuestionOptionModel.QuestionOptionsID > 0)
                                {
                                    objQuestionModel.QuestionOptionsList.Add(objQuestionOptionModel);
                                    if (objQuestionOptionModel.IsSelected)
                                    {
                                        //Set single and multi selection detail.
                                        if (!String.IsNullOrWhiteSpace(objQuestionModel.SelectedAnswers))
                                        {
                                            objQuestionModel.SelectedAnswers = objQuestionModel.SelectedAnswers + "," + Convert.ToString(objQuestionOptionModel.QuestionOptionsID);
                                        }
                                        else
                                        {
                                            objQuestionModel.SelectedAnswers = Convert.ToString(objQuestionOptionModel.QuestionOptionsID);
                                        }
                                    }
                                }
                                //fill question property
                                QuestionPropertyModel objQuestionPropertyModel = new QuestionPropertyModel();
                                objQuestionPropertyModel = GetDataRowToEntity <QuestionPropertyModel>(dtFilter.Rows[j]);
                                if (objQuestionPropertyModel != null && !objQuestionModel.QuestionPropertyList.Any(a => a.QuestionTypeID == objQuestionPropertyModel.QuestionTypeID && a.QuestionPropertyID == objQuestionPropertyModel.QuestionPropertyID))
                                {
                                    objQuestionModel.QuestionPropertyList.Add(objQuestionPropertyModel);
                                }
                            }
                            objDocumentResponseDetailModel.Questions.Add(objQuestionModel);
                        }
                    }

                    //fill Document result detail
                    objDocumentResponseDetailModel.Result = GetDataRowToEntity <DocumentResultModel>(dtDocument.Tables[1].Rows[0]);
                }
            }
            return(objDocumentResponseDetailModel);
        }
        //[Filters.Authorized]
        public ActionResult SaveDocumentResponse(DocumentResponseDetailModel objDocumentDetailModel)
        {
            try
            {
                if (objDocumentDetailModel.Result != null)
                {
                    Boolean IsRedirect = false;
                    //Get action type
                    switch (objDocumentDetailModel.ActionType.ToLower())
                    {
                    case "previous":
                        objDocumentDetailModel.CurrentPage = objDocumentDetailModel.CurrentPage - 1;
                        break;

                    case "next":
                        objDocumentDetailModel.CurrentPage = objDocumentDetailModel.CurrentPage + 1;
                        break;

                    case "custom":
                        objDocumentDetailModel.CurrentPage = objDocumentDetailModel.CurrentPage;
                        break;

                    //Save
                    case "save":
                        IsRedirect = true;
                        break;

                    case "submit":
                        IsRedirect = true;
                        objDocumentDetailModel.Result.IsCompleted = true;

                        break;
                    }

                    //objDocumentDetailModel.Result.NoOfAttempt = objDocumentDetailModel.Result.NoOfAttempt == 0 ? 1 : objDocumentDetailModel.Result.NoOfAttempt;
                    objDocumentDetailModel.CommonCreatedBy = LoggedInUserID;
                    for (int i = 0; i < objDocumentDetailModel.Questions.Count(); i++)
                    {
                        if (!string.IsNullOrWhiteSpace(objDocumentDetailModel.Questions[i].SelectedAnswers))
                        {
                            //radio or checkbox
                            if (objDocumentDetailModel.Questions[i].SelectedAnswers.Split(',').Length > 0)
                            {
                                //checkbox
                                if (objDocumentDetailModel.Questions[i].QuestionOptionsList != null)
                                {
                                    for (int j = 0; j < objDocumentDetailModel.Questions[i].QuestionOptionsList.Count(); j++)
                                    {
                                        //options
                                        if (objDocumentDetailModel.Questions[i].SelectedAnswers.Split(',').Contains(Convert.ToString(objDocumentDetailModel.Questions[i].QuestionOptionsList[j].QuestionOptionsID)))
                                        {
                                            objDocumentDetailModel.Questions[i].QuestionOptionsList[j].IsSelected = true;
                                        }
                                        else
                                        {
                                            objDocumentDetailModel.Questions[i].QuestionOptionsList[j].IsSelected = false;
                                        }
                                    }
                                }
                            }
                        }
                    }


                    //answer into xml from model
                    if (objDocumentDetailModel.Questions != null)
                    {
                        objDocumentDetailModel.QuestionAnswerXml  = string.Empty;
                        objDocumentDetailModel.QuestionAnswerXml += CommonUtils.GetBulkXML(objDocumentDetailModel.Questions);
                    }

                    //objDocumentDetailModel.Result.DocumentTargetAudienceID = LoggedInUserID;

                    //Insert or Update Document Question  Answer
                    serviceResponse        = objUtilityWeb.PostAsJsonAsync(WebApiURL.DocumentResponse + "/InsertUpdateDocumentResult", objDocumentDetailModel);
                    objDocumentDetailModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <DocumentResponseDetailModel>().Result : null;

                    //objDocumentDetailModel = objBLDocumentResponse.InsertUpdateDocumentResult(objDocumentDetailModel);
                    DocumentResponseDetailModel objTemp = GetDocumentResponse(objDocumentDetailModel, true);


                    if (objDocumentDetailModel.Questions.Where(x => x.QuestionType == RepidShare.Utility.CommonUtils.QuestionType.Price_Question.ToString()).ToList().Count > 0)
                    {
                        var objPrice_Temp     = objTemp.Questions.Where(x => x.QuestionType == RepidShare.Utility.CommonUtils.QuestionType.Price_Question.ToString()).ToList();
                        var objPrice_Question = objDocumentDetailModel.Questions.Where(x => x.QuestionType == RepidShare.Utility.CommonUtils.QuestionType.Price_Question.ToString()).ToList();
                        for (int i = 0; i < objPrice_Question.Count; i++)
                        {
                            if (objPrice_Temp.Where(x => x.QuestionID == objPrice_Question[i].QuestionID).ToList().Count > 0 && objPrice_Question[i].ResultDetailID == 0)
                            {
                                objPrice_Question[i].ResultDetailID = objPrice_Temp.Where(x => x.QuestionID == objPrice_Question[i].QuestionID).FirstOrDefault().ResultDetailID;
                            }
                            DataTable dtPriceDetails = new DataTable();
                            //dtPriceDetails.Columns.Add("ResultDetailId"); dtPriceDetails.Columns.Add("QuestionId"); dtPriceDetails.Columns.Add("InstAmt");
                            //dtPriceDetails.Columns.Add("TaxAmt"); dtPriceDetails.Columns.Add("IneteAmt"); dtPriceDetails.Columns.Add("TotalAmt");
                            //dtPriceDetails.Columns.Add("DateAmt");dtPriceDetails.Columns.Add("PenaltyAmt");

                            objPrice_Question[i].objPriceQuestionModel.QuestionId = objPrice_Question[i].QuestionID;
                            //objPrice_Question[i].objPriceQuestionModel.ResultDetailId = objPrice_Question[i].ResultDetailID;
                            objPrice_Question[i].objPriceQuestionModel.PrintAmt = !string.IsNullOrWhiteSpace(objPrice_Question[i].AnswerDetail) ? Convert.ToDecimal((objPrice_Question[i].AnswerDetail)) : 0;

                            if (!string.IsNullOrWhiteSpace(objPrice_Question[i].objPriceQuestionModel.TableInnerHTML))
                            {
                                string[] TableRows = objPrice_Question[i].objPriceQuestionModel.TableInnerHTML.Split(new string[] { "~" }, StringSplitOptions.RemoveEmptyEntries);
                                for (int k = 0; k < TableRows.Length; k++)
                                {
                                    string[] TableCols = TableRows[k].Split(new string[] { "&" }, StringSplitOptions.RemoveEmptyEntries);
                                    decimal  InstAmt   = 0;
                                    if (!string.IsNullOrWhiteSpace(TableCols[0]) && Convert.ToDecimal(TableCols[0]) > 0)
                                    {
                                        InstAmt = Convert.ToDecimal(TableCols[0]);
                                    }
                                    else
                                    {
                                        InstAmt = 0;
                                    }

                                    decimal TaxAmt = objPrice_Question[i].objPriceQuestionModel.TaxAmt;

                                    decimal IneteAmt = 0;;
                                    if (!string.IsNullOrWhiteSpace(objPrice_Question[i].objPriceQuestionModel.FixedAmt) && Convert.ToDecimal(objPrice_Question[i].objPriceQuestionModel.FixedAmt) == 1)
                                    {
                                        IneteAmt = Convert.ToDecimal(TableCols[1]);
                                    }
                                    else if (!string.IsNullOrWhiteSpace(objPrice_Question[i].objPriceQuestionModel.FixedAmt) && Convert.ToDecimal(objPrice_Question[i].objPriceQuestionModel.FixedAmt) == 0)
                                    {
                                        IneteAmt = Convert.ToDecimal(TableCols[1]);
                                    }
                                    else if (!string.IsNullOrWhiteSpace(objPrice_Question[i].objPriceQuestionModel.FixedAmt) && Convert.ToDecimal(objPrice_Question[i].objPriceQuestionModel.FixedAmt) == 3)
                                    {
                                        if (Convert.ToDecimal(TableCols[1]) > 0)
                                        {
                                            IneteAmt = InstAmt / Convert.ToDecimal(TableCols[1]);
                                        }
                                        else
                                        {
                                            IneteAmt = 0;
                                        }
                                    }
                                    else
                                    {
                                        IneteAmt = 0;
                                    }

                                    decimal TotalAmt   = InstAmt + TaxAmt + IneteAmt;
                                    string  DateAmt    = TableCols[2];
                                    string  PenaltyAmt = TableCols[3];
                                    objPrice_Question[i].objPriceQuestionModel.dtPriceDetails.Add(
                                        new PriceDetailsQuestionModel
                                    {
                                        ResultDetailId = objPrice_Question[i].objPriceQuestionModel.ResultDetailId,
                                        QuestionId     = objPrice_Question[i].objPriceQuestionModel.QuestionId,
                                        InstAmt        = InstAmt,
                                        TaxAmt         = TaxAmt,
                                        IneteAmt       = IneteAmt,
                                        TotalAmt       = TotalAmt,
                                        DateAmt        = DateAmt,
                                        PenaltyAmt     = PenaltyAmt
                                    });
                                }
                            }


                            serviceResponse = objUtilityWeb.PostAsJsonAsync(WebApiURL.DocumentResponse + "/InsertUpdatePriceQuestion", objPrice_Question[i].objPriceQuestionModel);
                            objPrice_Question[i].objPriceQuestionModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <PriceQuestionModel>().Result : null;
                        }
                    }



                    if (objDocumentDetailModel.ErrorCode == 0)
                    {
                        ModelState.Clear();

                        //if Error code is 0 than set Save Success Message and Redirect

                        //save & submit
                        if (IsRedirect)
                        {
                            //Session["ResultSucessMessage"] = objDocumentDetailModel.Result.IsCompleted ? String.Format(CommonResource.msgSubmitSuccess, "Document Response") : String.Format(CommonResource.msgSaveSuccess, "Document Response");
                            //return Json(new { url = "/User/MyDocument", JsonRequestBehavior.AllowGet });
                            return(Json(new { url = "/User/SummaryView", JsonRequestBehavior.AllowGet }));
                        }
                        //next preview
                        else
                        {
                            string redirecturl = "/DocumentResponse/SaveDocumentResponse?prm=" + CommonUtils.Encrypt("userid=" + objDocumentDetailModel.UserId + "&Documentid=" + objDocumentDetailModel.DocumentID + "&pagename=" + objDocumentDetailModel.UrlPageName + "&currentpage=" + objDocumentDetailModel.CurrentPage + "");

                            return(Json(new { url = redirecturl, JsonRequestBehavior.AllowGet }));
                        }
                    }
                    else
                    {
                        GetDocumentResponse(objDocumentDetailModel, true);
                        //if Error Code is not 0 than set error message
                        //objDocumentDetailModel.Message = String.Format(CommonResource.msgSaveError, "Document Response");
                        objDocumentDetailModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "DocumentResponse", "SaveDocumentResponse Post");
                //if Error Code is not 0 than set error message
                //objDocumentDetailModel.Message = String.Format(CommonResource.msgSaveError, "Document Response");
                objDocumentDetailModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
            }
            ModelState.AddModelError(string.Empty, "AJAX Post");
            return(PartialView("_SaveDocumentQueAnsList", objDocumentDetailModel));
        }
        /// <summary>
        /// Save Document response
        /// </summary>
        /// <returns></returns>
        //[Filters.MenuAccess]
        public ActionResult SaveDocumentResponse(string prm)
        {
            //Object of Model.
            DocumentResponseDetailModel objDocumentDetailModel = new DocumentResponseDetailModel();

            try
            {
                int    userid      = 0;
                int    DocumentID  = 0;
                String PageName    = string.Empty;
                int    currentpage = 1;
                //check query string
                if (!String.IsNullOrEmpty(prm))
                {
                    //Decrypt
                    string inputParameter = CommonUtils.Decrypt(prm).ToString().Replace("?", "").ToLower();

                    //get query string value
                    if (inputParameter.IndexOf("userid") > -1 || inputParameter.IndexOf("documentid") > -1)
                    {
                        foreach (var item in inputParameter.Split('&'))
                        {
                            if (item.IndexOf("userid") > -1)
                            {
                                int.TryParse(item.Replace("userid=", ""), out userid);
                            }
                            if (item.IndexOf("documentid") > -1)
                            {
                                int.TryParse(item.Replace("documentid=", ""), out DocumentID);
                            }
                            if (item.IndexOf("pagename") > -1)
                            {
                                PageName = Convert.ToString(item.Replace("pagename=", ""));
                            }
                            if (item.IndexOf("currentpage") > -1)
                            {
                                int.TryParse(item.Replace("currentpage=", ""), out currentpage);
                            }
                        }
                    }
                }

                objDocumentDetailModel.UrlPageName = PageName;

                if (string.IsNullOrWhiteSpace(PageName))
                {
                    //objDocumentDetailModel.ReferralUrl = "/Document/myDocument";
                    //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewUserDocument;// "My Documents";
                    objDocumentDetailModel.ReferralUrl = "/User/SummaryView";
                    objDocumentDetailModel.UrlTitle    = "User";
                }
                else if (string.IsNullOrWhiteSpace(objDocumentDetailModel.ReferralUrl))
                {
                    switch (PageName)
                    {
                    //case "home":
                    //    objDocumentDetailModel.ReferralUrl = "/Home/Home";
                    //    objDocumentDetailModel.UrlTitle = "Home";

                    //    break;
                    case "myDocument":
                        objDocumentDetailModel.ReferralUrl = "/User/myDocument";
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewUserDocument;//"My Documents";
                        break;

                    case "Documentuser":
                        objDocumentDetailModel.ReferralUrl = "/Document/viewDocumentuser?prm=" + CommonUtils.Encrypt(Convert.ToString(DocumentID));
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewDocumentUser;// "View Document User";
                        break;

                    default:
                        objDocumentDetailModel.ReferralUrl = "/User/myDocument";
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewUserDocument;//"My Documents";
                        break;
                    }
                }

                //Set default parameter
                objDocumentDetailModel.DocumentID        = DocumentID;
                objDocumentDetailModel.UserId            = LoggedInUserID;
                objDocumentDetailModel.ApplicationRoleID = ApplicationRoleId;
                objDocumentDetailModel.CurrentPage       = currentpage;
                objDocumentDetailModel.PageSize          = 1;
                objDocumentDetailModel.IsReadOnly        = false;
                //fill Document response detail model from database.
                objDocumentDetailModel = GetDocumentResponse(objDocumentDetailModel, true);

                /* if @ErrorCode =50 then Unautorized
                 * if @ErrorCode =51 then Document not published
                 * if @ErrorCode =52 then Document completed
                 * if @ErrorCode =53 then Document expired
                 * if @ErrorCode =54 then Document response completed and multiple response not allowed
                 * if @ErrorCode =55 then Document response not exist
                 * if @ErrorCode =56 then Document response already started by mobile.
                 * if @ErrorCode =61 then Document not exists.
                 */
                switch (objDocumentDetailModel.ErrorCode)
                {
                case 50:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgSaveDocumentUnauthorized;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 51:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentNotPublished;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 52:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentCompleted;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 53:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentExpired;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 54:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentSingleResponse;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 55:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentResponseNotExist;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 56:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentByMobile;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 61:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResource.msgDocumentNotExist;
                    return(Redirect(objDocumentDetailModel.ReferralUrl));
                }


                for (int i = 0; i < objDocumentDetailModel.Questions.Count; i++)
                {
                    if (objDocumentDetailModel.Questions[i].QuestionType == RepidShare.Utility.CommonUtils.QuestionType.Price_Question.ToString())
                    {
                        objDocumentDetailModel.Questions[i].objPriceQuestionModel                = new PriceQuestionModel();
                        objDocumentDetailModel.Questions[i].objPriceQuestionModel.QuestionId     = objDocumentDetailModel.Questions[i].QuestionID;
                        objDocumentDetailModel.Questions[i].objPriceQuestionModel.ResultDetailId = objDocumentDetailModel.Questions[i].ResultDetailID;
                        serviceResponse = objUtilityWeb.PostAsJsonAsync(WebApiURL.DocumentResponse + "/GetPriceQuestion", objDocumentDetailModel.Questions[i].objPriceQuestionModel);
                        objDocumentDetailModel.Questions[i].objPriceQuestionModel = serviceResponse.StatusCode == HttpStatusCode.OK ? serviceResponse.Content.ReadAsAsync <PriceQuestionModel>().Result : null;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, "DocumentResponse", "SaveDocumentResponse Get");
                //objDocumentDetailModel.Message = String.Format(DocumentResponse.msgViewDocumentError, "Save Document Response");
                objDocumentDetailModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
            }
            return(View(objDocumentDetailModel));
        }
        /// <summary>
        /// View Document response
        /// </summary>
        /// <returns></returns>
        //[Filters.MenuAccess]
        public ActionResult ViewDocumentResponse(string prm)
        {
            //Object of Model.
            DocumentResponseDetailModel objDocumentDetailModel = new DocumentResponseDetailModel();

            try
            {
                int    userid     = 0;
                int    DocumentID = 0;
                String PageName   = string.Empty;

                if (!String.IsNullOrEmpty(prm))
                {
                    //Decrypt query string
                    string inputParameter = CommonUtils.Decrypt(prm).ToString().Replace("?", "").ToLower();

                    //get query string vaule and set into paramtere of userid, Documentid and pagename
                    if (inputParameter.IndexOf("userid") > -1 || inputParameter.IndexOf("Documentid") > -1)
                    {
                        foreach (var item in inputParameter.Split('&'))
                        {
                            //id of the user to see response
                            if (item.IndexOf("userid") > -1)
                            {
                                int.TryParse(item.Replace("userid=", ""), out userid);
                            }
                            //id of Document
                            if (item.IndexOf("Documentid") > -1)
                            {
                                int.TryParse(item.Replace("Documentid=", ""), out DocumentID);
                            }
                            // Name of the page from where this url open
                            if (item.IndexOf("pagename") > -1)
                            {
                                PageName = Convert.ToString(item.Replace("pagename=", ""));
                            }
                        }
                    }
                }

                //check page name is blank or null
                if (string.IsNullOrWhiteSpace(PageName))
                {
                    //if its null then by default set referral url to my Document.
                    //objDocumentDetailModel.ReferralUrl = "/Document/myDocument";
                    //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewUserDocument;//"My Documents";
                    objDocumentDetailModel.ReferralUrl = "/Home/Home";
                    objDocumentDetailModel.UrlTitle    = "Home";
                }
                else if (string.IsNullOrWhiteSpace(objDocumentDetailModel.ReferralUrl))
                {
                    //check where from this page url is open
                    switch (PageName)
                    {
                    case "home":
                        // come from Home page.
                        objDocumentDetailModel.ReferralUrl = "/Home/Home";
                        objDocumentDetailModel.UrlTitle    = "Home";

                        break;

                    case "myDocument":
                        //come from My Document page.
                        objDocumentDetailModel.ReferralUrl = "/Document/myDocument";
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewUserDocument;//  "My Documents";
                        break;

                    case "Documentuser":
                        //come from View Document user
                        objDocumentDetailModel.ReferralUrl = "/Document/viewDocumentuser?prm=" + CommonUtils.Encrypt(Convert.ToString(DocumentID));
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewDocumentUser;// "View Document User";
                        break;

                    default:
                        //by default set to my Document page.
                        objDocumentDetailModel.ReferralUrl = "/Document/myDocument";
                        //objDocumentDetailModel.UrlTitle = IIMSDocumentEntities.Resource.DocumentResource.lblViewUserDocument;//"My Documents";
                        break;
                    }
                }


                //Set default parameter
                objDocumentDetailModel.DocumentID        = DocumentID;
                objDocumentDetailModel.UserId            = userid;
                objDocumentDetailModel.ApplicationRoleID = ApplicationRoleId;
                objDocumentDetailModel.NoOfAttempt       = 0;
                objDocumentDetailModel.CurrentPage       = 1;
                objDocumentDetailModel.PageSize          = CommonUtils.PageSize;
                objDocumentDetailModel.IsReadOnly        = true;

                //Get Document response detail model from database.
                //Set false for view Document

                GetDocumentResponse(objDocumentDetailModel, false);

                /* if @ErrorCode =50 then Unautorized
                 * if @ErrorCode =51 then Document not published
                 * if @ErrorCode =52 then Document completed
                 * if @ErrorCode =53 then Document expired
                 * if @ErrorCode =54 then Document response completed and multiple response not allowed
                 * if @ErrorCode =55 then Document response not exist
                 */
                //check error code
                switch (objDocumentDetailModel.ErrorCode)
                {
                case 50:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgViewDocumentUnauthorized;
                    //return RedirectToAction("MyDocument", "Document");
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 55:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResponse.msgDocumentResponseNotExist;
                    //return RedirectToAction("MyDocument", "Document");
                    return(Redirect(objDocumentDetailModel.ReferralUrl));

                case 61:
                    //Session["ResultNoticeMessage"] = IIMSDocumentEntities.Resource.DocumentResource.msgDocumentNotExist;
                    //return RedirectToAction("MyDocument", "Document");
                    return(Redirect(objDocumentDetailModel.ReferralUrl));
                }
            }
            //if there is any error exception then set error message and log detail of error into database.
            catch (Exception ex)
            {
                ErrorLog(ex, "DocumentResponse", "ViewDocumentResponse GET");
                //objDocumentDetailModel.Message = String.Format(DocumentResponse.msgViewDocumentError, "View Document Response");
                objDocumentDetailModel.MessageType = CommonUtils.MessageType.Error.ToString().ToLower();
            }
            //return view
            return(View(objDocumentDetailModel));
        }
        /// <summary>
        /// Get  Document Response For view
        /// </summary>
        /// <param name="ObjDocumentApplicationMappingDetail"></param>
        /// <returns></returns>
        public DocumentResponseDetailModel GetDocumentResponseForView(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            DLDocumentResponse objDLDocumentResponse = new DLDocumentResponse();
            //Get Document response detail with Document ,question , question property , question option and Document result.
            DataTable dtDocument = objDLDocumentResponse.GetDocumentResponseForView(objDocumentResponseDetailModel);

            if (dtDocument != null && dtDocument.Rows.Count > 0)
            {
                if (objDocumentResponseDetailModel != null)
                {
                    //fill Document master detail
                    int maxAttempt  = 0;
                    int noOfAttempt = 0;
                    int.TryParse(Convert.ToString(dtDocument.Rows[0]["MaxNoOfAttempt"]), out maxAttempt);
                    objDocumentResponseDetailModel.MaxNoOfAttempt = maxAttempt;

                    int.TryParse(Convert.ToString(dtDocument.Rows[0]["NoOfAttempt"]), out noOfAttempt);
                    objDocumentResponseDetailModel.NoOfAttempt = noOfAttempt;
                    //1. Fill Document detail  and application mapping detail

                    //objDocumentResponseDetailModel.DocumentApplicationDetail = GetDataRowToEntity<DocumentApplicationMappingModel>(dtDocument.Rows[0]);

                    //2. fill Document question details
                    objDocumentResponseDetailModel.Questions = new List <ViewQuestionAnswerModel>();

                    for (int i = 0; i < dtDocument.Rows.Count; i++)
                    {
                        ViewQuestionAnswerModel objQuestionModel = new ViewQuestionAnswerModel();
                        //get question from list
                        objQuestionModel = GetDataRowToEntity <ViewQuestionAnswerModel>(dtDocument.Rows[i]);

                        if (objQuestionModel != null && !objDocumentResponseDetailModel.Questions.Any(a => a.QuestionID == objQuestionModel.QuestionID))
                        {
                            DataView ViewQuestion = new DataView(dtDocument);
                            //Filter question into view
                            ViewQuestion.RowFilter = "QuestionID=" + objQuestionModel.QuestionID;
                            DataTable dtFilter = ViewQuestion.ToTable();
                            objQuestionModel.QuestionOptionsList  = new List <QuestionOptionsModel>();
                            objQuestionModel.QuestionPropertyList = new List <QuestionPropertyModel>();
                            for (int j = 0; j < dtFilter.Rows.Count; j++)
                            {
                                //fill question option detail
                                QuestionOptionsModel objQuestionOptionModel = new QuestionOptionsModel();
                                objQuestionOptionModel = GetDataRowToEntity <QuestionOptionsModel>(dtFilter.Rows[j]);
                                if (objQuestionOptionModel != null && objQuestionOptionModel.QuestionOptionsID > 0)
                                {
                                    objQuestionModel.QuestionOptionsList.Add(objQuestionOptionModel);
                                    //get detail of single/multi selection
                                    if (objQuestionOptionModel.IsSelected)
                                    {
                                        if (!String.IsNullOrWhiteSpace(objQuestionModel.SelectedAnswers))
                                        {
                                            objQuestionModel.SelectedAnswers = objQuestionModel.SelectedAnswers + "," + Convert.ToString(objQuestionOptionModel.QuestionOptionsID);
                                        }
                                        else
                                        {
                                            objQuestionModel.SelectedAnswers = Convert.ToString(objQuestionOptionModel.QuestionOptionsID);
                                        }
                                    }
                                }
                                //fill question property
                                QuestionPropertyModel objQuestionPropertyModel = new QuestionPropertyModel();
                                objQuestionPropertyModel = GetDataRowToEntity <QuestionPropertyModel>(dtFilter.Rows[j]);
                                if (objQuestionPropertyModel != null && !objQuestionModel.QuestionPropertyList.Any(a => a.QuestionTypeID == objQuestionPropertyModel.QuestionTypeID && a.QuestionPropertyID == objQuestionPropertyModel.QuestionPropertyID))
                                {
                                    objQuestionModel.QuestionPropertyList.Add(objQuestionPropertyModel);
                                }
                            }
                            objDocumentResponseDetailModel.Questions.Add(objQuestionModel);
                        }
                    }

                    //fill result detail
                    objDocumentResponseDetailModel.Result = GetDataRowToEntity <DocumentResultModel>(dtDocument.Rows[0]);

                    int totalRecord = Convert.ToInt32(dtDocument.Rows[0]["TotalCount"]);
                    //calculating total paging
                    objDocumentResponseDetailModel.TotalPages = TotalPage(totalRecord, objDocumentResponseDetailModel.PageSize);
                }
            }
            return(objDocumentResponseDetailModel);
        }
        /// <summary>
        /// Get Document response detail
        /// </summary>
        /// <param name="ObjDocumentApplicationMappingDetail"></param>
        /// <returns></returns>
        public DocumentResponseDetailModel GetDocumentPreview(DocumentResponseDetailModel objDocumentResponseDetailModel)
        {
            //objDocumentResponseDetailModel.DocumentApplicationDetail = new DocumentApplicationMappingModel();
            DLDocumentResponse objDLDocumentResponse = new DLDocumentResponse();
            //Get Document with question detail into datatable
            DataTable dtDocument = objDLDocumentResponse.GetDocumentPreview(objDocumentResponseDetailModel);

            if (dtDocument != null && dtDocument.Rows.Count > 0)
            {
                if (objDocumentResponseDetailModel != null)
                {
                    //1. Fill Document detail  and application mapping detail

                    //objDocumentResponseDetailModel.DocumentApplicationDetail = GetDataRowToEntity<DocumentApplicationMappingModel>(dtDocument.Rows[0]);

                    //2. fill Document question details
                    objDocumentResponseDetailModel.Questions = new List <ViewQuestionAnswerModel>();

                    for (int i = 0; i < dtDocument.Rows.Count; i++)
                    {
                        ViewQuestionAnswerModel objQuestionModel = new ViewQuestionAnswerModel();
                        //get question from list
                        objQuestionModel = GetDataRowToEntity <ViewQuestionAnswerModel>(dtDocument.Rows[i]);

                        if (objQuestionModel != null && !objDocumentResponseDetailModel.Questions.Any(a => a.QuestionID == objQuestionModel.QuestionID))
                        {
                            DataView ViewQuestion = new DataView(dtDocument);
                            ViewQuestion.RowFilter = "QuestionID=" + objQuestionModel.QuestionID;
                            DataTable dtFilter = ViewQuestion.ToTable();
                            objQuestionModel.QuestionOptionsList  = new List <QuestionOptionsModel>();
                            objQuestionModel.QuestionPropertyList = new List <QuestionPropertyModel>();
                            for (int j = 0; j < dtFilter.Rows.Count; j++)
                            {
                                //fill question option detail
                                QuestionOptionsModel objQuestionOptionModel = new QuestionOptionsModel();
                                objQuestionOptionModel = GetDataRowToEntity <QuestionOptionsModel>(dtFilter.Rows[j]);
                                if (objQuestionOptionModel != null && objQuestionOptionModel.QuestionOptionsID > 0)
                                {
                                    objQuestionModel.QuestionOptionsList.Add(objQuestionOptionModel);
                                    if (objQuestionOptionModel.IsSelected)
                                    {
                                        if (!String.IsNullOrWhiteSpace(objQuestionModel.SelectedAnswers))
                                        {
                                            objQuestionModel.SelectedAnswers = objQuestionModel.SelectedAnswers + "," + Convert.ToString(objQuestionOptionModel.QuestionOptionsID);
                                        }
                                        else
                                        {
                                            objQuestionModel.SelectedAnswers = Convert.ToString(objQuestionOptionModel.QuestionOptionsID);
                                        }
                                    }
                                }
                                //fill question property
                                QuestionPropertyModel objQuestionPropertyModel = new QuestionPropertyModel();
                                objQuestionPropertyModel = GetDataRowToEntity <QuestionPropertyModel>(dtFilter.Rows[j]);
                                if (objQuestionPropertyModel != null && !objQuestionModel.QuestionPropertyList.Any(a => a.QuestionTypeID == objQuestionPropertyModel.QuestionTypeID && a.QuestionPropertyID == objQuestionPropertyModel.QuestionPropertyID))
                                {
                                    objQuestionModel.QuestionPropertyList.Add(objQuestionPropertyModel);
                                }
                            }
                            objDocumentResponseDetailModel.Questions.Add(objQuestionModel);
                        }
                    }
                }
            }
            return(objDocumentResponseDetailModel);
        }