public ActionResult SaveSettings(string formid)
        {
            int CurrentOrgId = int.Parse(Session["SelectedOrgId"].ToString());
            List <FormsHierarchyDTO> FormList       = GetFormsHierarchy(formid);
            FormSettingRequest       FormSettingReq = new Enter.Common.Message.FormSettingRequest();
            int UserId = SurveyHelper.GetDecryptUserId(Session["UserId"].ToString());

            foreach (var Form in FormList)
            {
                FormSettingReq.GetXml          = true;
                FormSettingReq.FormInfo.FormId = new Guid(formid).ToString();
                FormSettingReq.FormInfo.UserId = UserId;
                FormSettingDTO FormSetting = new FormSettingDTO();
                FormSetting.FormId                 = Form.FormId;
                FormSetting.ColumnNameList         = GetDictionary(this.Request.Form["SelectedColumns_" + Form.FormId]);
                FormSetting.AssignedUserList       = GetDictionary(this.Request.Form["SelectedUser"]);
                FormSetting.SelectedOrgList        = GetDictionary(this.Request.Form["SelectedOrg"]);
                FormSetting.IsShareable            = GetBoolValue(this.Request.Form["IsShareable"]);
                FormSetting.SelectedDataAccessRule = int.Parse(this.Request.Form["DataAccessRuleId"]);

                if (!string.IsNullOrEmpty(this.Request.Form["SoftDeleteForm"]) && this.Request.Form["SoftDeleteForm"].ToUpper() == "ON")
                {
                    FormSetting.IsDisabled = true;
                }
                if (!string.IsNullOrEmpty(this.Request.Form["RemoveTestData"]) && this.Request.Form["RemoveTestData"].ToUpper() == "ON")
                {
                    FormSetting.DeleteDraftData = true;
                }
                FormSettingReq.FormSetting.Add(FormSetting);
                FormSettingReq.FormInfo.IsDraftMode = GetBoolValue(this.Request.Form["Mode"]);
                FormSettingReq.CurrentOrgId         = CurrentOrgId;
            }
            FormSettingResponse FormSettingResponse = _isurveyFacade.SaveSettings(FormSettingReq);



            bool IsMobileDevice = this.Request.Browser.IsMobileDevice;

            var model = new FormResponseInfoModel();


            model = GetFormResponseInfoModel(formid, 1, "", "", CurrentOrgId);

            if (IsMobileDevice == false)
            {
                if (!string.IsNullOrEmpty(this.Request.Form["SoftDeleteForm"]) && this.Request.Form["SoftDeleteForm"].ToUpper() == "ON")
                {
                    return(Json(null));
                }
                else
                {
                    return(PartialView("ListResponses", model));
                }
            }
            else
            {
                return(View("ListResponses", model));
            }
        }
        public ActionResult GetSettings(string formid)//List<FormInfoModel> ModelList, string formid)
        {
            FormSettingRequest FormSettingReq = new Enter.Common.Message.FormSettingRequest();
            List <KeyValuePair <int, string> > TempColumns = new List <KeyValuePair <int, string> >();
            //Get All forms
            List <FormsHierarchyDTO> FormsHierarchy = GetFormsHierarchy(formid);
            // List<FormSettingResponse> FormSettingResponseList = new List<FormSettingResponse>();
            List <SettingsInfoModel> ModelList = new List <SettingsInfoModel>();

            foreach (var Item in FormsHierarchy)
            {
                FormSettingReq.GetXml          = true;
                FormSettingReq.FormInfo.FormId = new Guid(Item.FormId).ToString();
                FormSettingReq.FormInfo.UserId = SurveyHelper.GetDecryptUserId(Session["UserId"].ToString());
                FormSettingReq.CurrentOrgId    = int.Parse(Session["SelectedOrgId"].ToString());
                //Getting Column Name  List

                FormSettingResponse FormSettingResponse = _isurveyFacade.GetFormSettings(FormSettingReq);
                //  FormSettingResponseList.Add(FormSettingResponse);



                // FormSettingResponse FormSettingResponse = _isurveyFacade.GetFormSettings(FormSettingReq);
                Columns     = FormSettingResponse.FormSetting.ColumnNameList.ToList();
                TempColumns = Columns;
                Columns.Sort(Compare);


                Dictionary <int, string> dictionary = Columns.ToDictionary(pair => pair.Key, pair => pair.Value);
                SettingsInfoModel        Model      = new SettingsInfoModel();
                Model.SelectedControlNameList = dictionary;

                Columns = FormSettingResponse.FormSetting.FormControlNameList.ToList();
                // Get Additional Metadata columns
                if (!FormSettingResponse.FormInfo.IsSQLProject)
                {
                    var MetaDataColumns = Epi.Web.MVC.Constants.Constant.MetaDaTaColumnNames();
                    Dictionary <int, string> Columndictionary = TempColumns.ToDictionary(pair => pair.Key, pair => pair.Value);

                    foreach (var item in MetaDataColumns)
                    {
                        if (!Columndictionary.ContainsValue(item))
                        {
                            Columns.Add(new KeyValuePair <int, string>(Columns.Count() + 1, item));
                        }
                    }

                    Columns.Sort(Compare);
                }

                Dictionary <int, string> dictionary1 = Columns.ToDictionary(pair => pair.Key, pair => pair.Value);

                Model.FormControlNameList = dictionary1;



                Columns = FormSettingResponse.FormSetting.AssignedUserList.ToList();
                if (Columns.Exists(col => col.Value == Session["UserEmailAddress"].ToString()))
                {
                    Columns.Remove(Columns.First(u => u.Value == Session["UserEmailAddress"].ToString()));
                }

                //Columns.Sort(Compare);

                Dictionary <int, string> dictionary2 = Columns.ToDictionary(pair => pair.Key, pair => pair.Value);

                Model.AssignedUserList = dictionary2;



                Columns = FormSettingResponse.FormSetting.UserList.ToList();

                if (Columns.Exists(col => col.Value == Session["UserEmailAddress"].ToString()))
                {
                    Columns.Remove(Columns.First(u => u.Value == Session["UserEmailAddress"].ToString()));
                }
                //Columns.Sort(Compare);

                Dictionary <int, string> dictionary3 = Columns.ToDictionary(pair => pair.Key, pair => pair.Value);

                Model.UserList = dictionary3;

                Columns = FormSettingResponse.FormSetting.AvailableOrgList.ToList();
                Dictionary <int, string> dictionary4 = Columns.ToDictionary(pair => pair.Key, pair => pair.Value);
                Model.AvailableOrgList = dictionary4;

                Columns = FormSettingResponse.FormSetting.SelectedOrgList.ToList();
                Dictionary <int, string> dictionary5 = Columns.ToDictionary(pair => pair.Key, pair => pair.Value);
                Model.SelectedOrgList = dictionary5;

                Model.IsShareable            = FormSettingResponse.FormInfo.IsShareable;
                Model.IsDraftMode            = FormSettingResponse.FormInfo.IsDraftMode;
                Model.FormOwnerFirstName     = FormSettingResponse.FormInfo.OwnerFName;
                Model.FormOwnerLastName      = FormSettingResponse.FormInfo.OwnerLName;
                Model.FormName               = FormSettingResponse.FormInfo.FormName;
                Model.FormId                 = Item.FormId;
                Model.DataAccessRuleIds      = FormSettingResponse.FormSetting.DataAccessRuleIds;
                Model.SelectedDataAccessRule = FormSettingResponse.FormSetting.SelectedDataAccessRule;
                Model.HasDraftModeData       = FormSettingResponse.FormInfo.HasDraftModeData;
                var DataAccessRuleDescription = "";
                foreach (var item in FormSettingResponse.FormSetting.DataAccessRuleDescription)
                {
                    DataAccessRuleDescription = DataAccessRuleDescription + item.Key.ToString() + " : " + item.Value + "\n";
                }

                Model.DataAccessRuleDescription = DataAccessRuleDescription;
                ModelList.Add(Model);
            }
            return(PartialView("Settings", ModelList));
        }
        public FormResponseInfoModel GetFormResponseInfoModel(string SurveyId, int PageNumber, string sort = "", string sortfield = "", int orgid = -1)
        {
            int UserId = SurveyHelper.GetDecryptUserId(Session["UserId"].ToString());
            FormResponseInfoModel FormResponseInfoModel = new FormResponseInfoModel();

            FormResponseInfoModel.SearchModel = new SearchBoxModel();
            SurveyResponseXML SurveyResponseXML = new SurveyResponseXML();

            if (!string.IsNullOrEmpty(SurveyId))
            {
                SurveyAnswerRequest FormResponseReq = new SurveyAnswerRequest();
                FormSettingRequest  FormSettingReq  = new Enter.Common.Message.FormSettingRequest();

                //Populating the request

                FormSettingReq.FormInfo.FormId = SurveyId;
                FormSettingReq.FormInfo.UserId = UserId;
                //Getting Column Name  List
                FormSettingReq.CurrentOrgId = orgid;
                FormSettingReq.FormInfoOnly = true;
                FormSettingResponse FormSettingResponse = _isurveyFacade.GetFormSettings(FormSettingReq);   //Pain Point
                Columns = FormSettingResponse.FormSetting.ColumnNameList.ToList();
                Columns.Sort(Compare);

                // Setting  Column Name  List
                FormResponseInfoModel.Columns = Columns;

                FormResponseInfoModel.FormInfoModel.IsShared    = FormSettingResponse.FormInfo.IsShared;
                FormResponseInfoModel.FormInfoModel.IsShareable = FormSettingResponse.FormInfo.IsShareable;
                // Set User Role
                //if (FormResponseInfoModel.FormInfoModel.IsShared)
                //{

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

                FormResponseReq.Criteria.SurveyId           = SurveyId.ToString();
                FormResponseReq.Criteria.PageNumber         = PageNumber;
                FormResponseReq.Criteria.UserId             = UserId;
                FormResponseReq.Criteria.IsSqlProject       = FormSettingResponse.FormInfo.IsSQLProject;
                FormResponseReq.Criteria.IsShareable        = FormSettingResponse.FormInfo.IsShareable;
                FormResponseReq.Criteria.UserOrganizationId = orgid;
                Session["IsSqlProject"] = FormSettingResponse.FormInfo.IsSQLProject;
                Session["IsOwner"]      = FormSettingResponse.FormInfo.IsOwner;
                //if (Session["SearchCriteria"] != null)
                //{
                //    FormResponseInfoModel.SearchModel = (SearchBoxModel)Session["SearchCriteria"];
                //}
                // Following code retain search starts
                if (Session["SearchCriteria"] != null &&
                    !string.IsNullOrEmpty(Session["SearchCriteria"].ToString()) &&
                    (Request.QueryString["col1"] == null || Request.QueryString["col1"] == "undefined"))
                {
                    FormResponseReq.Criteria.SearchCriteria = Session["SearchCriteria"].ToString();
                    FormResponseInfoModel.SearchModel       = (SearchBoxModel)Session["SearchModel"];
                }
                else
                {
                    FormResponseReq.Criteria.SearchCriteria = CreateSearchCriteria(Request.QueryString, FormResponseInfoModel.SearchModel, FormResponseInfoModel);
                    Session["SearchModel"]    = FormResponseInfoModel.SearchModel;
                    Session["SearchCriteria"] = FormResponseReq.Criteria.SearchCriteria;
                }
                // Following code retain search ends
                PopulateDropDownlists(FormResponseInfoModel, FormSettingResponse.FormSetting.FormControlNameList.ToList());

                if (sort.Length > 0)
                {
                    FormResponseReq.Criteria.SortOrder = sort;
                }
                if (sortfield.Length > 0)
                {
                    FormResponseReq.Criteria.Sortfield = sortfield;
                }


                SurveyAnswerResponse FormResponseList = _isurveyFacade.GetFormResponseList(FormResponseReq);//Pain Point


                //var ResponseTableList ; //= FormSettingResponse.FormSetting.DataRows;
                //Setting Resposes List
                List <ResponseModel> ResponseList = new List <ResponseModel>();
                foreach (var item in FormResponseList.SurveyResponseList)
                {
                    if (item.SqlData != null)
                    {
                        ResponseList.Add(ConvertRowToModel(item, Columns));
                    }
                    else
                    {
                        ResponseList.Add(SurveyResponseXML.ConvertXMLToModel(item, Columns));
                    }
                }


                //foreach (var item in FormResponseList.SurveyResponseList)
                //{
                //    ResponseList.Add(SurveyResponseXML.ConvertXMLToModel(item, Columns));
                //}

                FormResponseInfoModel.ResponsesList = ResponseList;
                //Setting Form Info
                FormResponseInfoModel.FormInfoModel = Mapper.ToFormInfoModel(FormResponseList.FormInfo);
                //Setting Additional Data

                FormResponseInfoModel.NumberOfPages     = FormResponseList.NumberOfPages;
                FormResponseInfoModel.PageSize          = ReadPageSize();
                FormResponseInfoModel.NumberOfResponses = FormResponseList.NumberOfResponses;
                FormResponseInfoModel.sortfield         = sortfield;
                FormResponseInfoModel.sortOrder         = sort;
                FormResponseInfoModel.CurrentPage       = PageNumber;
            }
            return(FormResponseInfoModel);
        }