protected FormResponseInfoModel GetFormResponseInfoModel(string surveyId, int orgId, int userId)
        {
            FormResponseInfoModel formResponseInfoModel = new FormResponseInfoModel();

            formResponseInfoModel.SearchModel = new SearchBoxModel();
            var surveyResponseBuilder             = new SurveyResponseBuilder();
            FormSettingRequest formSettingRequest = new FormSettingRequest {
                ProjectId = GetStringSessionValue(UserSession.Key.ProjectId)
            };

            //Populating the request

            formSettingRequest.FormInfo.FormId = surveyId;
            formSettingRequest.FormInfo.UserId = userId;
            //Getting Column Name  List
            formSettingRequest.CurrentOrgId = orgId;
            var formSettingResponse = formResponseInfoModel.FormSettingResponse = _surveyFacade.GetFormSettings(formSettingRequest);

            formSettingResponse.FormSetting.FormId = surveyId;
            _columns = formSettingResponse.FormSetting.ColumnNameList.ToList();
            _columns.Sort(Compare);
            _columnDigests = formSettingResponse.FormSetting.ColumnDigestList.ToList();
            _columnDigests.Sort(Compare);

            // Setting  Column Name  List
            formResponseInfoModel.Columns       = _columns;
            formResponseInfoModel.ColumnDigests = _columnDigests;

            return(formResponseInfoModel);
        }
Example #2
0
        public SurveyFacade(IDataEntryService dataEntryService,
                            ISurveyInfoService surveyInfoService,
                            IFormSettingsService formSettingsService,
                            ISecurityFacade securityFacade,

                            SurveyResponseBuilder surveyResponseBuilder,
                            IProjectMetadataProvider projectMetadataProvider,

                            Epi.Cloud.Common.Message.SurveyInfoRequest surveyInfoRequest,
                            Epi.Cloud.Common.Message.SurveyAnswerRequest surveyResponseRequest,
                            Epi.Cloud.Common.Message.UserAuthenticationRequest surveyAuthenticationRequest,

                            SurveyAnswerDTO surveyAnswerDTO,
                            FormInfoDTO formInfoDTO)
        {
            _dataEntryService        = dataEntryService;
            _surveyInfoService       = surveyInfoService;
            _formSettingsService     = formSettingsService;
            _securityFacade          = securityFacade;
            _surveyResponseBuilder   = surveyResponseBuilder;
            _projectMetadataProvider = projectMetadataProvider;

            _surveyInfoRequest   = surveyInfoRequest;
            _surveyAnswerRequest = surveyResponseRequest;
            _surveyAnswerDTO     = surveyAnswerDTO;
            _formInfoDTO         = formInfoDTO;
        }
        public FormResponseInfoModel GetFormResponseInfoModel(string surveyId, int pageNumber, string sort = "", string sortfield = "", int orgid = -1)
        {
            // Initialize the Metadata Accessor
            MetadataAccessor.CurrentFormId = /*FromURL*/ surveyId;

            FormResponseInfoModel formResponseInfoModel = null;

            int    orgId    = GetIntSessionValue(UserSession.Key.CurrentOrgId);
            int    userId   = GetIntSessionValue(UserSession.Key.UserId);
            string userName = GetStringSessionValue(UserSession.Key.UserName);

            if (!string.IsNullOrEmpty(/*FromURL*/ surveyId))
            {
                formResponseInfoModel = GetFormResponseInfoModel(/*FromURL*/ surveyId, orgid, userId);
                FormSettingResponse formSettingResponse = formResponseInfoModel.FormSettingResponse;

                var surveyResponseBuilder = new SurveyResponseBuilder();

                formResponseInfoModel.FormInfoModel.IsShared    = formSettingResponse.FormInfo.IsShared;
                formResponseInfoModel.FormInfoModel.IsShareable = formSettingResponse.FormInfo.IsShareable;
                formResponseInfoModel.FormInfoModel.FormName    = formSettingResponse.FormInfo.FormName;
                formResponseInfoModel.FormInfoModel.FormNumber  = formSettingResponse.FormInfo.FormNumber;


                // Set User Role
                SetUserRole(userId, orgid);

                // If this is the first grid query or the user elects to return to page 1 then
                // clear the QuerySetToken which will retrieve a new grid response set which may
                // include newly created records.
                if (pageNumber <= 1)
                {
                    RemoveSessionValue(UserSession.Key.QuerySetToken);
                }

                var responseContext = InitializeResponseContext(formId: surveyId);

                SurveyAnswerRequest formResponseReq = new SurveyAnswerRequest {
                    ResponseContext = responseContext
                };
                formResponseReq.Criteria.SurveyId           = /*FromURL*/ surveyId;
                formResponseReq.Criteria.PageNumber         = pageNumber;
                formResponseReq.Criteria.UserId             = userId;
                formResponseReq.Criteria.IsSqlProject       = formSettingResponse.FormInfo.IsSQLProject;
                formResponseReq.Criteria.IsShareable        = formSettingResponse.FormInfo.IsShareable;
                formResponseReq.Criteria.DataAccessRuleId   = formSettingResponse.FormSetting.SelectedDataAccessRule;
                formResponseReq.Criteria.IsDraftMode        = formSettingResponse.FormInfo.IsDraftMode;
                formResponseReq.Criteria.UserOrganizationId = orgid;

                SetSessionValue(UserSession.Key.IsSqlProject, formSettingResponse.FormInfo.IsSQLProject);
                SetSessionValue(UserSession.Key.IsOwner, formSettingResponse.FormInfo.IsOwner);

                // Following code retain search starts
                string sessionSearchCriteria = GetStringSessionValue(UserSession.Key.SearchCriteria, defaultValue: null);
                if (!string.IsNullOrEmpty(sessionSearchCriteria) &&
                    (Request.QueryString["col1"] == null || Request.QueryString["col1"] == "undefined"))
                {
                    formResponseReq.Criteria.SearchCriteria = sessionSearchCriteria;
                    formResponseInfoModel.SearchModel       = GetSessionValue <SearchBoxModel>(UserSession.Key.SearchModel);
                }
                else
                {
                    formResponseReq.Criteria.SearchCriteria = CreateSearchCriteria(Request.QueryString, formResponseInfoModel.SearchModel, formResponseInfoModel);
                    SetSessionValue(UserSession.Key.SearchModel, formResponseInfoModel.SearchModel);
                    SetSessionValue(UserSession.Key.SearchCriteria, formResponseReq.Criteria.SearchCriteria);
                }
                // Following code retain search ends
                PopulateDropDownlists(formResponseInfoModel, formSettingResponse.FormSetting.FormControlNameList.ToList());

                if (sort != null && sort.Length > 0)
                {
                    formResponseReq.Criteria.SortOrder = sort;
                }
                else
                {
                    formResponseReq.Criteria.SortOrder = AppSettings.GetStringValue(AppSettings.Key.DefaultSortOrder);
                }
                if (sortfield.Length > 0)
                {
                    formResponseReq.Criteria.Sortfield = sortfield;
                }
                else
                {
                    formResponseReq.Criteria.Sortfield = AppSettings.GetStringValue(AppSettings.Key.DefaultSortField);
                }

                formResponseReq.Criteria.SurveyQAList     = _columns.ToDictionary(c => c.Key.ToString(), c => c.Value);
                formResponseReq.Criteria.FieldDigestList  = formResponseInfoModel.ColumnDigests.ToDictionary(c => c.Key, c => c.Value);
                formResponseReq.Criteria.SearchDigestList = ToSearchDigestList(formResponseInfoModel.SearchModel, /*FromURL*/ surveyId);
                formResponseReq.Criteria.QuerySetToken    = GetStringSessionValue(UserSession.Key.QuerySetToken, null);

                SurveyAnswerResponse surveyAnswerResponse = _surveyFacade.GetFormResponseList(formResponseReq);

                // Remember the QuerySetToken to assure the same set of responses is queried if the user
                // navigates to some other page in the response grid.
                SetSessionValue(UserSession.Key.QuerySetToken, surveyAnswerResponse.QuerySetToken);

                formResponseInfoModel.ResponsesList = surveyAnswerResponse.SurveyResponseList.Select(r => r.ToResponseModel(_columns)).ToList();

                //Setting Form Info
                formResponseInfoModel.FormInfoModel = surveyAnswerResponse.FormInfo.ToFormInfoModel();

                //Setting Additional Data
                formResponseInfoModel.NumberOfPages     = surveyAnswerResponse.NumberOfPages;
                formResponseInfoModel.PageSize          = surveyAnswerResponse.NumberOfResponsesPerPage;
                formResponseInfoModel.NumberOfResponses = surveyAnswerResponse.NumberOfResponses;
                formResponseInfoModel.sortfield         = sortfield;
                formResponseInfoModel.sortOrder         = sort;
                formResponseInfoModel.CurrentPage       = pageNumber;
            }
            return(formResponseInfoModel);
        }
        public ActionResult Index(string surveyId, string addNewFormId, string editForm)
        {
            // Assign "editForm" parameter to a less confusing name.
            // editForm contains the responseId of the record being edited.
            string editResponseId = editForm;

            bool isNewRecord;

            int    orgId    = GetIntSessionValue(UserSession.Key.CurrentOrgId);
            int    userId   = GetIntSessionValue(UserSession.Key.UserId);
            string userName = GetStringSessionValue(UserSession.Key.UserName);

            SetSessionValue(UserSession.Key.FormValuesHasChanged, string.Empty);

            var editResponseIdFromSession = GetStringSessionValue(UserSession.Key.EditResponseId);

            if (string.IsNullOrEmpty(editResponseId) && editResponseIdFromSession != null)
            {
                editResponseId = editResponseIdFromSession;
            }

            if (!string.IsNullOrEmpty(editResponseId) && string.IsNullOrEmpty(addNewFormId))
            {
                // -------------------------------
                //      Edit Existing Record
                // -------------------------------
                isNewRecord = false;
                SetSessionValue(UserSession.Key.RootResponseId, editResponseId);

                SetSessionValue(UserSession.Key.IsEditMode, true);
                SurveyAnswerDTO surveyAnswerDTO = GetSurveyAnswer(editResponseId, GetStringSessionValue(UserSession.Key.RootFormId));

                SetSessionValue(UserSession.Key.RequestedViewId, surveyAnswerDTO.ViewId);

                surveyAnswerDTO.RecoverLastRecordVersion = GetBoolSessionValue(UserSession.Key.RecoverLastRecordVersion);

                RemoveSessionValue(UserSession.Key.RecoverLastRecordVersion);
                return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = editResponseId, PageNumber = 1, surveyid = surveyAnswerDTO.SurveyId, Edit = "Edit" }));
            }

            // -------------------------------
            //      Add New Record
            // -------------------------------
            isNewRecord = true;
            SetSessionValue(UserSession.Key.IsEditMode, false);
            bool isMobileDevice = this.Request.Browser.IsMobileDevice;


            if (isMobileDevice == false)
            {
                isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
            }

            FormsAuthentication.SetAuthCookie("BeginSurvey", false);

            //create the responseid
            Guid responseId = Guid.NewGuid();

            TempData[TempDataKeys.ResponseId] = responseId.ToString();

            // create the first survey response
            // Epi.Cloud.Common.DTO.SurveyAnswerDTO SurveyAnswer = _isurveyFacade.CreateSurveyAnswer(surveyModel.SurveyId, ResponseID.ToString());
            SetSessionValue(UserSession.Key.RootFormId, addNewFormId);
            var rootResponseId = responseId;

            SetSessionValue(UserSession.Key.RootResponseId, rootResponseId);

            var responseContext = InitializeResponseContext(formId: addNewFormId, responseId: responseId.ToString(), isNewRecord: true) as ResponseContext;

            SurveyAnswerDTO surveyAnswer = _surveyFacade.CreateSurveyAnswer(responseContext);

            surveyId = /*FromURL*/ surveyId ?? surveyAnswer.SurveyId;

            // Initialize the Metadata Accessor
            MetadataAccessor.CurrentFormId = surveyId;

            MvcDynamicForms.Form form            = _surveyFacade.GetSurveyFormData(surveyAnswer.SurveyId, 1, surveyAnswer, isMobileDevice);
            SurveyInfoModel      surveyInfoModel = form.SurveyInfo.ToFormInfoModel();

            MetadataAccessor metadataAccessor = form.SurveyInfo as MetadataAccessor;

            // set the survey answer to be production or test
            surveyAnswer.IsDraftMode = form.SurveyInfo.IsDraftMode;

            TempData[TempDataKeys.Width] = form.Width + 100;

            string checkcode = MetadataAccessor.GetFormDigest(surveyId).CheckCode;

            form.FormCheckCodeObj = form.GetCheckCodeObj(metadataAccessor.GetFieldDigests(surveyId), surveyAnswer.ResponseDetail, checkcode);

            ///////////////////////////// Execute - Record Before - start//////////////////////
            Dictionary <string, string> contextDetailList = new Dictionary <string, string>();
            EnterRule             functionObject_B        = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
            SurveyResponseBuilder surveyResponseBuilder   = new SurveyResponseBuilder(_requiredList);

            if (functionObject_B != null && !functionObject_B.IsNull())
            {
                try
                {
                    PageDigest[] pageDigests    = form.MetadataAccessor.GetCurrentFormPageDigests();
                    var          responseDetail = surveyAnswer.ResponseDetail;

                    responseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigests);
                    SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList);
                    _requiredList           = surveyResponseBuilder.RequiredList;
                    form.RequiredFieldsList = _requiredList;
                    functionObject_B.Context.HiddenFieldList      = form.HiddenFieldsList;
                    functionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList;
                    functionObject_B.Context.DisabledFieldList    = form.DisabledFieldsList;
                    functionObject_B.Context.RequiredFieldList    = form.RequiredFieldsList;

                    functionObject_B.Execute();

                    // field list
                    form.HiddenFieldsList      = functionObject_B.Context.HiddenFieldList;
                    form.HighlightedFieldsList = functionObject_B.Context.HighlightedFieldList;
                    form.DisabledFieldsList    = functionObject_B.Context.DisabledFieldList;
                    form.RequiredFieldsList    = functionObject_B.Context.RequiredFieldList;


                    contextDetailList = Epi.Cloud.MVC.Utility.SurveyHelper.GetContextDetailList(functionObject_B);
                    form = Epi.Cloud.MVC.Utility.SurveyHelper.UpdateControlsValuesFromContext(form, contextDetailList);

                    _surveyFacade.UpdateSurveyResponse(surveyInfoModel,
                                                       responseId.ToString(),
                                                       form,
                                                       surveyAnswer,
                                                       false,
                                                       false,
                                                       0,
                                                       orgId,
                                                       userId,
                                                       userName);
                }
                catch (Exception ex)
                {
                    // do nothing so that processing
                    // can continue
                }
            }
            else
            {
                PageDigest[] pageDigestArray = metadataAccessor.GetPageDigests(surveyInfoModel.SurveyId);

                surveyAnswer.ResponseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigestArray);

                _requiredList = surveyResponseBuilder.RequiredList;
                SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList);
                form.RequiredFieldsList = _requiredList;
            }

            ///////////////////////////// Execute - Record Before - End//////////////////////
            return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = responseId, PageNumber = 1, surveyid = surveyInfoModel.SurveyId }));
        }
Example #5
0
        private FormResponseInfoModel GetFormResponseInfoModels(string surveyId, string responseId, List <FormsHierarchyDTO> formsHierarchyDTOList = null)
        {
            FormResponseInfoModel formResponseInfoModel = new FormResponseInfoModel();

            var formHieratchyDTO = formsHierarchyDTOList.FirstOrDefault(h => h.FormId == surveyId);

            SurveyResponseBuilder surveyResponseBuilder = new SurveyResponseBuilder();

            if (!string.IsNullOrEmpty(surveyId))
            {
                SurveyAnswerRequest surveyAnswerRequest = new SurveyAnswerRequest();
                FormSettingRequest  formSettingRequest  = new FormSettingRequest {
                    ProjectId = GetStringSessionValue(UserSession.Key.ProjectId)
                };

                //Populating the request

                formSettingRequest.FormInfo.FormId = surveyId;
                formSettingRequest.FormInfo.UserId = GetIntSessionValue(UserSession.Key.UserId);
                //Getting Column Name  List
                FormSettingResponse formSettingResponse = _surveyFacade.GetFormSettings(formSettingRequest);
                _columns = formSettingResponse.FormSetting.ColumnNameList.ToList();
                _columns.Sort(Compare);

                // Setting  Column Name  List
                formResponseInfoModel.Columns = _columns;

                //Getting Resposes
                var ResponseListDTO = formsHierarchyDTOList.FirstOrDefault(x => x.FormId == surveyId).ResponseIds;

                // If we don't have any data for this child form yet then create a response
                if (ResponseListDTO.Count == 0)
                {
                    var formResponseDetail = InitializeFormResponseDetail();
                    formResponseDetail.ParentResponseId = responseId;
                    formResponseDetail.ResponseId       = Guid.NewGuid().ToString();
                    formResponseDetail.ResolveMetadataDependencies();

                    var surveyAnswerDTO = new SurveyAnswerDTO(formResponseDetail);
                    surveyAnswerDTO.CurrentPageNumber = 1;
                    ResponseListDTO.Add(surveyAnswerDTO);
                }

                //Setting Resposes List
                List <ResponseModel> ResponseList = new List <ResponseModel>();
                foreach (var item in ResponseListDTO)
                {
                    if (item.ParentResponseId == responseId)
                    {
                        if (item.SqlData != null)
                        {
                            ResponseList.Add(ConvertRowToModel(item, _columns, "ChildGlobalRecordID"));
                        }
                        else
                        {
                            ResponseList.Add(item.ToResponseModel(_columns));
                        }
                    }
                }

                formResponseInfoModel.ResponsesList = ResponseList;

                formResponseInfoModel.PageSize = ReadPageSize();

                formResponseInfoModel.CurrentPage = 1;
            }
            return(formResponseInfoModel);
        }
Example #6
0
        public FormResponseInfoModel GetSurveyResponseInfoModel(string surveyId, int pageNumber, string sort = "", string sortfield = "", int orgid = -1)
        {
            // Initialize the Metadata Accessor
            MetadataAccessor.CurrentFormId = surveyId;

            FormResponseInfoModel formResponseInfoModel = null;
            int    orgId    = GetIntSessionValue(UserSession.Key.CurrentOrgId);
            int    userId   = GetIntSessionValue(UserSession.Key.UserId);
            string userName = GetStringSessionValue(UserSession.Key.UserName);

            if (!string.IsNullOrEmpty(surveyId))
            {
                formResponseInfoModel = GetFormResponseInfoModel(surveyId, orgid, userId);
                FormSettingResponse formSettingResponse = formResponseInfoModel.FormSettingResponse;
                var surveyResponseBuilder = new SurveyResponseBuilder();
                formResponseInfoModel.FormInfoModel.IsShared    = formSettingResponse.FormInfo.IsShared;
                formResponseInfoModel.FormInfoModel.IsShareable = formSettingResponse.FormInfo.IsShareable;
                formResponseInfoModel.FormInfoModel.FormName    = formSettingResponse.FormInfo.FormName;
                formResponseInfoModel.FormInfoModel.FormNumber  = formSettingResponse.FormInfo.FormNumber;


                // Set User Role
                //if (formResponseInfoModel.FormInfoModel.IsShared)
                //{

                //    SetUserRole(UserId, orgid);
                //}
                //else
                //{
                //SetUserRole(UserId, FormSettingResponse.FormInfo.OrganizationId);
                //}
                //SetUserRole(userId, orgid);

                var responseContext = InitializeResponseContext(formId: surveyId);

                SurveyAnswerRequest formResponseReq = new SurveyAnswerRequest {
                    ResponseContext = responseContext
                };
                formResponseReq.Criteria.SurveyId         = surveyId.ToString();
                formResponseReq.Criteria.PageNumber       = /*FromURL*/ pageNumber;
                formResponseReq.Criteria.UserId           = userId;
                formResponseReq.Criteria.IsSqlProject     = formSettingResponse.FormInfo.IsSQLProject;
                formResponseReq.Criteria.IsShareable      = formSettingResponse.FormInfo.IsShareable;
                formResponseReq.Criteria.DataAccessRuleId = formSettingResponse.FormSetting.SelectedDataAccessRule;
                //formResponseReq.Criteria.IsMobile = true;
                formResponseReq.Criteria.UserOrganizationId = orgid;
                formResponseReq.Criteria.IsDraftMode        = formSettingResponse.FormInfo.IsDraftMode;

                SetSessionValue(UserSession.Key.IsSqlProject, formSettingResponse.FormInfo.IsSQLProject);
                SetSessionValue(UserSession.Key.IsOwner, formSettingResponse.FormInfo.IsOwner);

                // Following code retain search starts
                string sessionSearchCriteria = GetStringSessionValue(UserSession.Key.SearchCriteria, defaultValue: null);
                if (!string.IsNullOrEmpty(sessionSearchCriteria) &&
                    (Request.QueryString["col1"] == null || Request.QueryString["col1"] == "undefined"))
                {
                    formResponseReq.Criteria.SearchCriteria = sessionSearchCriteria;
                    formResponseInfoModel.SearchModel       = GetSessionValue <SearchBoxModel>(UserSession.Key.SearchModel);
                }
                else
                {
                    formResponseReq.Criteria.SearchCriteria = CreateSearchCriteria(Request.QueryString, formResponseInfoModel.SearchModel, formResponseInfoModel);
                    SetSessionValue(UserSession.Key.SearchModel, formResponseInfoModel.SearchModel);
                    SetSessionValue(UserSession.Key.SearchCriteria, formResponseReq.Criteria.SearchCriteria);
                }
                // Following code retain search ends
                PopulateDropDownlists(formResponseInfoModel, formSettingResponse.FormSetting.FormControlNameList.ToList());

                if (sort != null && sort.Length > 0)
                {
                    formResponseReq.Criteria.SortOrder = sort;
                }
                else
                {
                    formResponseReq.Criteria.SortOrder = AppSettings.GetStringValue(AppSettings.Key.DefaultSortOrder);
                }
                if (!string.IsNullOrEmpty(sortfield) && sortfield.Length > 0)
                {
                    formResponseReq.Criteria.Sortfield = sortfield;
                }
                else
                {
                    formResponseReq.Criteria.Sortfield = AppSettings.GetStringValue(AppSettings.Key.DefaultSortField);
                }
                formResponseReq.Criteria.SurveyQAList     = _columns.ToDictionary(c => c.Key.ToString(), c => c.Value);
                formResponseReq.Criteria.FieldDigestList  = formResponseInfoModel.ColumnDigests.ToDictionary(c => c.Key, c => c.Value);
                formResponseReq.Criteria.SearchDigestList = ToSearchDigestList(formResponseInfoModel.SearchModel, surveyId);


                SurveyAnswerResponse formResponseList = _surveyFacade.GetFormResponseList(formResponseReq);
                var surveyResponse = formResponseList.SurveyResponseList;//.Skip((pageNumber - 1) * 20).Take(20);

                formResponseList.SurveyResponseList = surveyResponse.ToList();
                List <ResponseModel>                responseList      = new List <ResponseModel>();
                List <ResponseModel>                responseListModel = new List <ResponseModel>();
                Dictionary <string, string>         dictory           = new Dictionary <string, string>();
                List <Dictionary <string, string> > dictoryList       = new List <Dictionary <string, string> >();;

                foreach (var item in formResponseList.SurveyResponseList)
                {
                    if (item.SqlData != null)
                    {
                        responseList.Add(ConvertRowToModel(item, _columns, "GlobalRecordId"));
                    }
                    else
                    {
                        responseList.Add(item.ToResponseModel(_columns));
                    }
                }

                string sortFieldcolumn = string.Empty;
                if (!string.IsNullOrEmpty(sortfield))
                {
                    foreach (var column in _columns)
                    {
                        if (column.Value == sortfield)
                        {
                            sortFieldcolumn = "Column" + column.Key;
                        }
                    }
                }

                var sortList = responseList;
                if (!string.IsNullOrEmpty(sortfield))
                {
                    if (sort != "ASC")
                    {
                        switch (sortFieldcolumn)
                        {
                        case "Column1":
                            responseListModel = sortList.OrderByDescending(x => x.Column1).ToList();
                            break;

                        case "Column2":
                            responseListModel = sortList.OrderByDescending(x => x.Column2).ToList();
                            break;

                        case "Column3":
                            responseListModel = sortList.OrderByDescending(x => x.Column3).ToList();
                            break;

                        case "Column4":
                            responseListModel = sortList.OrderByDescending(x => x.Column4).ToList();
                            break;

                        case "Column5":
                            responseListModel = sortList.OrderByDescending(x => x.Column5).ToList();
                            break;
                        }
                    }
                    else
                    {
                        switch (sortFieldcolumn)
                        {
                        case "Column1":
                            responseListModel = sortList.OrderBy(x => x.Column1).ToList();
                            break;

                        case "Column2":
                            responseListModel = sortList.OrderBy(x => x.Column2).ToList();
                            break;

                        case "Column3":
                            responseListModel = sortList.OrderBy(x => x.Column3).ToList();
                            break;

                        case "Column4":
                            responseListModel = sortList.OrderBy(x => x.Column4).ToList();
                            break;

                        case "Column5":
                            responseListModel = sortList.OrderBy(x => x.Column5).ToList();
                            break;
                        }
                    }
                    // formResponseInfoModel.ResponsesList = responseListModel.Skip((pageNumber - 1) * 20).Take(20).ToList();
                    formResponseInfoModel.ResponsesList = responseList.Take(20).ToList();
                }
                if (string.IsNullOrEmpty(sort))
                {
                    // formResponseInfoModel.ResponsesList = responseList.Skip((pageNumber - 1) * 20).Take(20).ToList();
                    formResponseInfoModel.ResponsesList = responseList.Take(20).ToList();
                }

                //Setting Form Info
                formResponseInfoModel.FormInfoModel = formResponseList.FormInfo.ToFormInfoModel();
                //Setting Additional Data

                formResponseInfoModel.NumberOfPages     = formResponseList.NumberOfPages;
                formResponseInfoModel.PageSize          = ReadPageSize();
                formResponseInfoModel.NumberOfResponses = formResponseList.NumberOfResponses;
                formResponseInfoModel.sortfield         = /*FromURL*/ sortfield;
                formResponseInfoModel.sortOrder         = /*FromURL*/ sort;
                formResponseInfoModel.CurrentPage       = /*FromURL*/ pageNumber;
            }
            return(formResponseInfoModel);
        }
Example #7
0
        public ActionResult Index(string surveyId, string addNewFormId, string editForm, string cancel)
        {
            // Assign "editForm" parameter to a less confusing name.
            // editForm contains the responseId of the record being edited.
            string editResponseId = editForm;

            int    userId         = GetIntSessionValue(UserSession.Key.UserId);
            string userName       = GetStringSessionValue(UserSession.Key.UserName);
            bool   isMobileDevice = this.Request.Browser.IsMobileDevice;

            FormsAuthentication.SetAuthCookie("BeginSurvey", false);
            bool isEditMode = false;

            if (isMobileDevice == true)
            {
                isMobileDevice = Epi.Cloud.MVC.Utility.SurveyHelper.IsMobileDevice(this.Request.UserAgent.ToString());
            }
            bool isAndroid = this.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0;

            if (!string.IsNullOrEmpty(/*FromURL*/ cancel))
            {
                int pageNumber;
                int.TryParse(/*FromURL*/ cancel, out pageNumber);
                Dictionary <string, int> surveyPagesList = GetSessionValue <Dictionary <string, int> >(UserSession.Key.RelateButtonPageId);
                if (surveyPagesList != null)
                {
                    pageNumber = surveyPagesList[this.Request.Form["Parent_Response_Id"].ToString()];
                }

                return(RedirectToRoute(new { Controller = "Survey", Action = "Index", responseid = this.Request.Form["Parent_Response_Id"].ToString(), PageNumber = pageNumber }));
            }
            if (string.IsNullOrEmpty(/*FromURL*/ editResponseId) && string.IsNullOrEmpty(/*FromURL*/ addNewFormId) && !IsSessionValueNull(UserSession.Key.EditResponseId))
            {
                editResponseId = GetStringSessionValue(UserSession.Key.EditResponseId);
            }

            if (!string.IsNullOrEmpty(editResponseId))
            {
                if (IsSessionValueNull(UserSession.Key.RootResponseId))
                {
                    SetSessionValue(UserSession.Key.RootResponseId, editResponseId);
                }

                isEditMode = true;
                SetSessionValue(UserSession.Key.IsEditMode, isEditMode);

                SurveyAnswerDTO surveyAnswer = GetSurveyAnswer(editResponseId, GetStringSessionValue(UserSession.Key.RootFormId));
                if (!IsSessionValueNull(UserSession.Key.RecoverLastRecordVersion))
                {
                    surveyAnswer.RecoverLastRecordVersion = GetBoolSessionValue(UserSession.Key.RecoverLastRecordVersion);
                }
                //   string childRecordId = GetChildRecordId(surveyAnswer);
                //return RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = surveyAnswer.ParentResponseId, PageNumber = 1, Edit = "Edit" });
                return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = editResponseId, PageNumber = 1, Edit = "Edit" }));
            }

            //create the responseid
            Guid responseId = Guid.NewGuid();

            if (IsSessionValueNull(UserSession.Key.RootResponseId))
            {
                SetSessionValue(UserSession.Key.RootResponseId, responseId);
            }

            var rootResponseId = GetStringSessionValue(UserSession.Key.RootResponseId);

            TempData[TempDataKeys.ResponseId] = responseId.ToString();

            int orgId = GetIntSessionValue(UserSession.Key.CurrentOrgId);

            var responseContext = InitializeResponseContext(formId: /*FromURL*/ addNewFormId, responseId: responseId.ToString(), parentResponseId: this.Request.Form["Parent_Response_Id"].ToString(), isNewRecord: !isEditMode);

            // create the first survey response
            SurveyAnswerDTO          surveyAnswerDTO  = _surveyFacade.CreateSurveyAnswer(responseContext);
            List <FormsHierarchyDTO> formsHierarchy   = GetFormsHierarchy();
            SurveyInfoModel          surveyInfoModel  = GetSurveyInfo(surveyAnswerDTO.SurveyId, formsHierarchy);
            MetadataAccessor         metadataAccessor = surveyInfoModel as MetadataAccessor;

            // set the survey answer to be production or test
            surveyAnswerDTO.IsDraftMode = surveyInfoModel.IsDraftMode;

            MvcDynamicForms.Form form = _surveyFacade.GetSurveyFormData(surveyAnswerDTO.SurveyId, 1, surveyAnswerDTO, isMobileDevice, null, formsHierarchy, isAndroid);

            TempData[TempDataKeys.Width] = form.Width + 100;

            var    formDigest = metadataAccessor.GetFormDigest(surveyAnswerDTO.SurveyId);
            string checkcode  = formDigest.CheckCode;

            FormResponseDetail responseDetail = surveyAnswerDTO.ResponseDetail;

            form.FormCheckCodeObj = form.GetCheckCodeObj(MetadataAccessor.GetFieldDigests(surveyAnswerDTO.SurveyId), responseDetail, checkcode);

            ///////////////////////////// Execute - Record Before - start//////////////////////
            Dictionary <string, string> ContextDetailList = new Dictionary <string, string>();
            EnterRule             functionObject_B        = (EnterRule)form.FormCheckCodeObj.GetCommand("level=record&event=before&identifier=");
            SurveyResponseBuilder surveyResponseBuilder   = new SurveyResponseBuilder(_requiredList);

            if (functionObject_B != null && !functionObject_B.IsNull())
            {
                try
                {
                    PageDigest[] pageDigests = form.MetadataAccessor.GetCurrentFormPageDigests();
                    responseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigests);

                    SetSessionValue(UserSession.Key.RequiredList, surveyResponseBuilder.RequiredList);
                    _requiredList           = surveyResponseBuilder.RequiredList;
                    form.RequiredFieldsList = _requiredList;
                    functionObject_B.Context.HiddenFieldList      = form.HiddenFieldsList;
                    functionObject_B.Context.HighlightedFieldList = form.HighlightedFieldsList;
                    functionObject_B.Context.DisabledFieldList    = form.DisabledFieldsList;
                    functionObject_B.Context.RequiredFieldList    = form.RequiredFieldsList;

                    functionObject_B.Execute();

                    // field list
                    form.HiddenFieldsList      = functionObject_B.Context.HiddenFieldList;
                    form.HighlightedFieldsList = functionObject_B.Context.HighlightedFieldList;
                    form.DisabledFieldsList    = functionObject_B.Context.DisabledFieldList;
                    form.RequiredFieldsList    = functionObject_B.Context.RequiredFieldList;


                    ContextDetailList = SurveyHelper.GetContextDetailList(functionObject_B);
                    form = SurveyHelper.UpdateControlsValuesFromContext(form, ContextDetailList);

                    _surveyFacade.UpdateSurveyResponse(surveyInfoModel, responseId.ToString(), form, surveyAnswerDTO, false, false, 0, orgId, userId, userName);
                }
                catch (Exception ex)
                {
                    // do nothing so that processing
                    // can continue
                }
            }
            else
            {
                PageDigest[] pageDigestArray = form.MetadataAccessor.GetCurrentFormPageDigests();// metadataAccessor.GetPageDigests(surveyInfoModel.SurveyId);

                surveyAnswerDTO.ResponseDetail = surveyResponseBuilder.CreateResponseDocument(responseContext, pageDigestArray);

                _requiredList = surveyResponseBuilder.RequiredList;
                SetSessionValue(UserSession.Key.RequiredList, _requiredList);
                form.RequiredFieldsList = _requiredList;
                _surveyFacade.UpdateSurveyResponse(surveyInfoModel, surveyAnswerDTO.ResponseId, form, surveyAnswerDTO, false, false, 0, orgId, userId, userName);
            }

            surveyAnswerDTO = (SurveyAnswerDTO)formsHierarchy.SelectMany(x => x.ResponseIds).FirstOrDefault(z => z.ResponseId == surveyAnswerDTO.ResponseId);

            ///////////////////////////// Execute - Record Before - End//////////////////////
            return(RedirectToAction(ViewActions.Index, ControllerNames.Survey, new { responseid = responseId, PageNumber = 1 }));
        }