Ejemplo n.º 1
0
        public FormSettingBO GetFormSettings()
        {
            FormSettingBO formSettingBO = new FormSettingBO();

            try
            {
                formSettingBO = DataAccessessRulesHelper.GetDataAccessRules(formSettingBO);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(formSettingBO);
        }
Ejemplo n.º 2
0
        public List <FormSettingBO> GetFormSettingsList(List <string> formIds, int currentOrgId)
        {
            List <FormSettingBO> formSettingBOList = _formSettingDao_EF.GetFormSettingsList(formIds, currentOrgId, userAndOrgInfoOnly: true);

            foreach (var formSettingBO in formSettingBOList)
            {
                int i = 1;
                formSettingBO.FormControlNameList = GetAllColumnNames(formSettingBO.FormId).ToDictionary(k => i++, v => v);
            }

            DataAccessessRulesHelper.GetDataAccessRules(formSettingBOList);

            var formSettingsList = GetFormSettings(formIds);

            formSettingBOList = FormSettingsExtensions.MergeInfoFormSettingBOList(formSettingsList, formSettingBOList);
            return(formSettingBOList);
        }
Ejemplo n.º 3
0
        public FormSettingBO GetFormSettings(string formId, int currentOrgId)
        {
            FormSettingBO formSettingBO = new FormSettingBO {
                FormId = formId
            };
            Dictionary <int, string> columnNameList = new Dictionary <int, string>();

            try
            {
                formSettingBO = _formSettingDao_EF.GetFormSettings(formId, currentOrgId, userAndOrgInfoOnly: true);
                int i = 1;
                formSettingBO.FormControlNameList = GetAllColumnNames(formId).ToDictionary(k => i++, v => v);
                formSettingBO = DataAccessessRulesHelper.GetDataAccessRules(formSettingBO);
                formSettingBO = GetFormSettings(formId).ToFormSettingBO(formSettingBO);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(formSettingBO);
        }
        public FormSettingBO GetFormSettings(string formId, int currentOrgId, bool userAndOrgInfoOnly)
        {
            FormSettingBO formSettingBO = new FormSettingBO {
                FormId = formId
            };
            Dictionary <int, string> availableUsers = new Dictionary <int, string>();
            Dictionary <int, string> selectedUsers  = new Dictionary <int, string>();
            Dictionary <int, string> availableOrgs  = new Dictionary <int, string>();
            Dictionary <int, string> selectedOrgs   = new Dictionary <int, string>();

            try
            {
                Guid id = new Guid(formId);
                using (var Context = DataObjectFactory.CreateContext())
                {
                    SurveyMetaData selectedUserQuery = Context.SurveyMetaDatas.First(x => x.SurveyId == id);

                    var selectedOrgId = currentOrgId;
                    var query         = (from user in selectedUserQuery.Users
                                         join userorg in Context.UserOrganizations
                                         on user.UserID equals userorg.UserID
                                         where userorg.Active == true && userorg.OrganizationID == selectedOrgId
                                         select user).Distinct().OrderBy(user => user.UserName);

                    foreach (var user in query)
                    {
                        selectedUsers.Add(user.UserID, user.UserName);
                    }

                    formSettingBO.AssignedUserList = selectedUsers;

                    // --------------------------------------------------------------------------------------------- \\

                    var userQuery = (from user in Context.Users
                                     join userorg in Context.UserOrganizations
                                     on user.UserID equals userorg.UserID
                                     where userorg.Active == true && userorg.OrganizationID == selectedOrgId
                                     //orderby user.UserName
                                     select user).Distinct().OrderBy(user => user.UserName);

                    foreach (var user in userQuery)
                    {
                        if (!selectedUsers.ContainsValue(user.UserName) && user.UserID != selectedUserQuery.OwnerId)
                        {
                            availableUsers.Add(user.UserID, user.UserName);
                        }
                    }

                    formSettingBO.UserList = availableUsers;

                    // --------------------------------------------------------------------------------------------- \\

                    //// Select Orgnization list
                    var OrganizationQuery = Context.Organizations.Where(c => c.SurveyMetaDatas.Any(a => a.SurveyId == id)).ToList();

                    foreach (var org in OrganizationQuery)
                    {
                        selectedOrgs.Add(org.OrganizationId, org.Organization1);
                    }
                    formSettingBO.SelectedOrgList = selectedOrgs;

                    // --------------------------------------------------------------------------------------------- \\

                    ////  Available Organization list
                    IQueryable <Organization> OrganizationList = Context.Organizations.ToList().AsQueryable();
                    foreach (var Org in OrganizationList)
                    {
                        if (!selectedOrgs.ContainsValue(Org.Organization1) && Org.IsEnabled == true)
                        {
                            availableOrgs.Add(Org.OrganizationId, Org.Organization1);
                        }
                    }
                    formSettingBO.AvailableOrgList = availableOrgs;

                    // --------------------------------------------------------------------------------------------- \\

                    if (!userAndOrgInfoOnly)
                    {
                        //// Response Grid Column Name List
                        Dictionary <int, string> ColumnNameList = new Dictionary <int, string>();

                        var Query = from response in Context.ResponseDisplaySettings
                                    where response.FormId == id
                                    select response;

                        var DataRow = Query;

                        // If there are no grid display columns currently defined
                        // then initialize the list to the first 5 fields in the form.
                        if (DataRow.Count() == 0)
                        {
                            var sortOrder = 1;
                            var responseGridColumnNames = GetFieldDigests(formId)
                                                          .Where(f => !FieldDigest.NonDataFieldTypes.Any(t => t == f.FieldType))
                                                          .Take(5)
                                                          .Select(f => ResponseDisplaySetting.CreateResponseDisplaySetting(id, f.TrueCaseFieldName, sortOrder++));
                            foreach (var responseDisplaySetting in responseGridColumnNames)
                            {
                                Context.AddToResponseDisplaySettings(responseDisplaySetting);
                                ColumnNameList.Add(responseDisplaySetting.SortOrder, responseDisplaySetting.ColumnName);
                            }
                            Context.SaveChanges();
                        }
                        else
                        {
                            foreach (var Row in DataRow)
                            {
                                ColumnNameList.Add(Row.SortOrder, Row.ColumnName);
                            }
                        }
                        formSettingBO.ResponseGridColumnNameList = ColumnNameList;

                        // --------------------------------------------------------------------------------------------- \\

                        //// Selected Data Access Rule Id
                        var MetaData = from r in Context.SurveyMetaDatas
                                       where r.SurveyId == id
                                       select new
                        {
                            Id = r.DataAccessRuleId
                        };

                        var selectedDataAccessRuleId = int.Parse(MetaData.First().Id.ToString());
                        formSettingBO.SelectedDataAccessRule = selectedDataAccessRuleId;

                        // --------------------------------------------------------------------------------------------- \\

                        //// Data Access Rules
                        Dictionary <int, string>    DataAccessRuleIds         = new Dictionary <int, string>();
                        Dictionary <string, string> DataAccessRuleDescription = new Dictionary <string, string>();

                        DataAccessessRulesHelper.GetDataAccessRules(out DataAccessRuleIds, out DataAccessRuleDescription);
                        formSettingBO.DataAccessRuleIds         = DataAccessRuleIds;
                        formSettingBO.DataAccessRuleDescription = DataAccessRuleDescription;

                        //IQueryable<DataAccessRule> RuleIDs = Context.DataAccessRules.ToList().AsQueryable();
                        //foreach (var Rule in RuleIDs)
                        //{
                        //    DataAccessRuleIds.Add(Rule.RuleId, Rule.RuleName);
                        //    DataAccessRuleDescription.Add(Rule.RuleName, Rule.RuleDescription);
                        //}

                        // --------------------------------------------------------------------------------------------- \\

                        //// All Column Names From MetadataAccessor
                        int k = 1;
                        formSettingBO.FormControlNameList = GetAllColumnNames(formId).ToDictionary(key => k++, value => value);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(formSettingBO);
        }