private int getNumAssmnts(UASEntities uasCntxt)
        {
            try
            {
                uas_Config config = uasCntxt.uas_Config.Where(c => c.ConfigName == "NoGridAssmnts").FirstOrDefault();

                if (config != null)
                {
                    uas_ProfileConfig profileConfig = uasCntxt.uas_ProfileConfig.Where(p => p.ConfigID == config.ConfigID).FirstOrDefault();

                    if (profileConfig != null)
                    {
                        uas_UserProfile userProfile = uasCntxt.uas_UserProfile.Where(u => u.ProfileConfigID == profileConfig.ProfileConfigID &&
                                                                                     u.UserID == SessionHelper.LoginStatus.UserID).FirstOrDefault();

                        if (userProfile != null)
                        {
                            return(Int32.Parse(userProfile.OptionSet));
                        }
                    }
                }
            }
            catch (Exception xcptn)
            {
                Debug.WriteLine("SearchModel.getNumAssmnts exception: " + xcptn.Message);
            }

            return(15);
        }
        private static void LoadJurisdictionDropdowns(UASEntities context, JurisdictionUnitModel model)
        {
            var units = from g in context.uas_Group
                        where g.GroupTypeID == 195
                        select g;

            model.Units = (from u in units
                           select new SelectListItem()
            {
                Text = u.GroupName,
                Value = u.GroupID.ToString()
            }).ToList();
        }
        private static void LoadJurisdictions(EnrollmentSiteModel model, UASEntities context)
        {
            var jurisdictions = from g in context.uas_Group
                                where g.GroupTypeID == 195
                                select g;

            model.Units = (from j in jurisdictions
                           select new SelectListItem()
            {
                Text = j.GroupName,
                Value = j.GroupID.ToString()
            }).ToList();
        }
        /// <summary>Database Context for the uas_ tables</summary>
        ///
        public static UASEntities getUasDbContext()
        {
            bool ventureMode = GetVentureMode();

            if (ventureMode)
            {
                Debug.WriteLine("GetDbContext Venture mode - using UASEntitiesVenture");
                UASEntities ue = new UASEntities("UASEntitiesVenture");
                ue.Database.Connection.ConnectionString = ventureConnectionString;
                return(ue);
            }

            return(new UASEntities("UASEntities"));
        }
Beispiel #5
0
        /// <summary>
        /// Gets data from the def_FormResults record for a form result
        /// </summary>
        /// <param name="formResult">The form result to get data from</param>
        /// <param name="form">The form result's form</param>
        /// <returns>ValuePairs containing identifier = label for a form result entry, value = the form result entry (string)</returns>
        public static List <ValuePair> GetFormResultValues(def_FormResults formResult, def_Forms form)
        {
            List <ValuePair> values = new List <ValuePair>();

            //number
            ValuePair valuePair = new ValuePair(FormResultExportTagName.recipientId.ToString(), formResult.subject.ToString());

            values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.formResultId.ToString(), formResult.formResultId.ToString());
            values.Add(valuePair);

            //^ SisId in csv second row

            //text
            valuePair = new ValuePair(FormResultExportTagName.identifier.ToString(), form.identifier);
            values.Add(valuePair);

            //add formId (number)
            valuePair = new ValuePair(FormResultExportTagName.formId.ToString(), form.formId.ToString());
            values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.group.ToString(), formResult.GroupID.ToString());
            values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.enterprise.ToString(), formResult.EnterpriseID.ToString());
            values.Add(valuePair);

            ////number
            //valuePair = new ValuePair(interviewerId, formResult.interviewer.ToString());
            //values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.assigned.ToString(), formResult.assigned.ToString());
            values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.statusId.ToString(), formResult.formStatus.ToString());
            values.Add(valuePair);

            //text
            valuePair = new ValuePair(FormResultExportTagName.dateUpdated.ToString(), formResult.dateUpdated.ToString());
            values.Add(valuePair);

            //text
            valuePair = new ValuePair(FormResultExportTagName.statusChangeDate.ToString(), formResult.statusChangeDate.ToString());
            values.Add(valuePair);

            valuePair = new ValuePair(FormResultExportTagName.deleted.ToString(), formResult.deleted.ToString());
            values.Add(valuePair);

            valuePair = new ValuePair(FormResultExportTagName.locked.ToString(), formResult.locked.ToString());
            values.Add(valuePair);

            valuePair = new ValuePair(FormResultExportTagName.archived.ToString(), formResult.archived.ToString());
            values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.reviewStatus.ToString(), formResult.reviewStatus.ToString());
            values.Add(valuePair);

            //number
            valuePair = new ValuePair(FormResultExportTagName.lastModifiedByUserId.ToString(), formResult.LastModifiedByUserId.ToString());
            values.Add(valuePair);

            //pull info that comes from other def tables
            using (formsEntities def = DataContext.GetDbContext())
            {
                try
                {
                    int    statusMasterId   = def.def_StatusMaster.Where(sm => sm.formId == 1 && sm.ApplicationId == 1).Select(sm => sm.statusMasterId).First();
                    int    statusDetailId   = def.def_StatusDetail.Where(sd => sd.statusMasterId == statusMasterId && sd.sortOrder == formResult.reviewStatus).Select(sd => sd.statusDetailId).First();
                    string reviewStatusText = def.def_StatusText.Where(st => st.statusDetailId == statusDetailId).Select(st => st.displayText).First();
                    valuePair = new ValuePair(FormResultExportTagName.reviewStatusText.ToString(), reviewStatusText);
                    values.Add(valuePair);
                }
                catch (Exception e) { Debug.WriteLine(e); }

                try
                {
                    valuePair = new ValuePair(FormResultExportTagName.statusText.ToString(),
                                              ((WebService.WSConstants.FR_formStatus)(formResult.formStatus)).ToString());
                    values.Add(valuePair);
                }
                catch (Exception e) { Debug.WriteLine(e); }
            }

            //pull info that comes from uas tables
            using (UASEntities uas = DataContext.getUasDbContext())
            {
                try
                {
                    valuePair = new ValuePair(FormResultExportTagName.groupName.ToString(),
                                              uas.uas_Group
                                              .Where(g => g.GroupID == formResult.GroupID)
                                              .Select(g => g.GroupName).First());
                    values.Add(valuePair);
                }
                catch (Exception e) { Debug.WriteLine(e); }

                try
                {
                    valuePair = new ValuePair(FormResultExportTagName.assignedLoginId.ToString(),
                                              uas.uas_User
                                              .Where(u => u.UserID == formResult.assigned)
                                              .Select(u => u.LoginID).First());
                    values.Add(valuePair);
                }
                catch (Exception e) { Debug.WriteLine(e); }

                try
                {
                    valuePair = new ValuePair(FormResultExportTagName.lastModifiedByLoginId.ToString(),
                                              uas.uas_User
                                              .Where(u => u.UserID == formResult.LastModifiedByUserId)
                                              .Select(u => u.LoginID).First());
                    values.Add(valuePair);
                }
                catch (Exception e) { Debug.WriteLine(e); }

                try
                {
                    valuePair = new ValuePair(FormResultExportTagName.enterpriseName.ToString(),
                                              uas.uas_Enterprise
                                              .Where(e => e.EnterpriseID == formResult.EnterpriseID)
                                              .Select(e => e.EnterpriseName).First());
                    values.Add(valuePair);
                }
                catch (Exception e) { Debug.WriteLine(e); }
            }

            return(values);
        }
        public SearchModel()
        {
            reviewAll = ReviewStatus.ReviewAll();

            permConst = new UAS.Business.PermissionConstants();

            VentureMode = SessionHelper.IsVentureMode;

            timeout = SessionHelper.SessionTotalTimeoutMinutes;

            try
            {
                if (SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets.Count() > 0)
                {
                    string permSet = SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets[0].PermissionSet;
                    edit       = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.EDIT, UAS.Business.PermissionConstants.ASSMNTS);
                    create     = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.CREATE, UAS.Business.PermissionConstants.ASSMNTS);
                    unlock     = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.UNLOCK, UAS.Business.PermissionConstants.ASSMNTS);
                    delete     = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.DELETE, UAS.Business.PermissionConstants.ASSMNTS);
                    archive    = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.ARCHIVE, UAS.Business.PermissionConstants.ASSMNTS);
                    undelete   = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.UNDELETE, UAS.Business.PermissionConstants.ASSMNTS);
                    editLocked = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.EDIT_LOCKED, UAS.Business.PermissionConstants.ASSMNTS);
                    move       = UAS_Business_Functions.hasPermission(permSet, UAS.Business.PermissionConstants.MOVE, UAS.Business.PermissionConstants.ASSMNTS);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Missing permissoin: " + ex.Message);
            }
            searchPref  = false;
            profilePref = false;
            passPref    = false;

            showSearch = true;

            UASEntities UASContext = DataContext.getUasDbContext();

            numAssmnts = getNumAssmnts(UASContext);

            EntAppConfig patternsForEnterprise = null;

            if (!SessionHelper.IsVentureMode)
            {
                AuthenticationClient webclient = new AuthenticationClient();
                var entConfig = webclient.GetEntAppConfigByEnumAndEnt("PATTERN_CHECK", SessionHelper.LoginStatus.EnterpriseID);
                if (entConfig != null && entConfig.ConfigValue == bool.TrueString)
                {
                    if (
                        UAS_Business_Functions.hasPermission(
                            SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets[0].PermissionSet,
                            PermissionConstants.PATT_CHECK, PermissionConstants.ASSMNTS))
                    {
                        ShowPatternCheck = true;
                    }
                }

                patternsForEnterprise = webclient.GetEntAppConfigByEnumAndEnt("PATTERNS_FOR_ENTERPRISE",
                                                                              SessionHelper.LoginStatus.EnterpriseID);

                if (patternsForEnterprise == null)
                {
                    patternsForEnterprise = webclient.GetEntAppConfigByEnumAndEnt("PATTERNS_FOR_ENTERPRISE", 0);
                }
            }

            //int grpPerm0Id = Assmnts.Infrastructure.SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets[0].GroupID;

            //int grpPerm1Id;
            //if (Assmnts.Infrastructure.SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets.Count() > 1)
            //{
            //    grpPerm1Id = Assmnts.Infrastructure.SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets[1].GroupID;
            //}
            //else
            //{
            //    grpPerm1Id = grpPerm0Id;
            //}

            /* **************************************************************
             * The statements below need to be replaced with pulling a variable
             * from the web.config file.
             * 'VentureMode'.
             *
             * Done 2/13/15 LK
             * Move up in function so can use to get timeout value if neccessary
             * 5/15/15 LK #12554
             *
             * **************************************************************
             */
            //if (!String.IsNullOrEmpty(strVentureMode))
            //{
            //    OfflineMode = Convert.ToBoolean(strVentureMode);
            //}

            /* string currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
             * OfflineMode = (currentPath.ToLower().Contains("venture")) ? true : false;
             */
            ShowAllAssessmentsForRecipient = false;  // Do not show all assessments for Recipient by default.

            DetailSearchCriteria = new SearchCriteria();

            DetailSearchCriteria.InterviewerList = new List <SelectListItem>();
            DetailSearchCriteria.EnterpriseList  = new List <SelectListItem>();
            DetailSearchCriteria.GroupList       = new List <SelectListItem>();
            DetailSearchCriteria.PatternList     = new List <SelectListItem>();

            DetailSearchCriteria.SelectedInterviewers = new List <string>();
            DetailSearchCriteria.SelectedEnts         = new List <int>();
            DetailSearchCriteria.SelectedGroups       = new List <int>();

            List <string>         interviewers = new List <string>();
            List <uas_Group>      groups       = new List <uas_Group>();
            List <uas_Enterprise> ents         = new List <uas_Enterprise>();

            int entId = Assmnts.Infrastructure.SessionHelper.LoginStatus.EnterpriseID;

            if (entId == 0)
            {
                interviewers = (from i in UASContext.uas_User
                                select i.LoginID).ToList();

                groups = (from g in UASContext.uas_Group
                          select g).ToList();

                ents = (from e in UASContext.uas_Enterprise
                        select e).ToList();
            }
            else
            {
                interviewers = (from i in UASContext.uas_User
                                where i.EnterpriseID == entId
                                select i.LoginID).ToList();

                ents = (from e in UASContext.uas_Enterprise
                        where e.EnterpriseID == entId
                        select e).ToList();


                //if (grpPerm0Id == 0)
                //{
                //    using (var UASContext = new SISEntities())
                //    {
                //        groups = (from g in UASContext.uas_Group
                //                  where g.EnterpriseID == entId
                //                  select g).ToList();
                //    }
                //}
                //else
                //{

                try
                {
                    if (SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups[0] == 0)
                    {
                        groups = UASContext.uas_Group.Where(g => g.EnterpriseID == entId).ToList();

                        //auth.GetGroupsByEnterprise(auth.GetEnterprise(entId)).Select(h => UASContext.uas_Group.FirstOrDefault(g => g.GroupID == h.GroupID)).ToList();
                    }
                    else
                    {
                        AppGroupPermissions agp = SessionHelper.LoginStatus.appGroupPermissions[0];
                        groups = UASContext.uas_Group.Where(g => agp.authorizedGroups.Contains(g.GroupID)).ToList();


                        //auth.GetChildGroups(entId, SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups[0])
                        //.Where(id => id > -1)
                        //.Select(groupId => UASContext.uas_Group.FirstOrDefault(g => g.GroupID == groupId)).ToList();
                        //groups = (from g in UASContext.uas_Group
                        //          where g.EnterpriseID == entId
                        //          && (g.GroupID == grpPerm0Id
                        //            || g.GroupID == grpPerm1Id)
                        //          select g).ToList();
                    }
                }
                //}
                catch (Exception ex) {
                    Debug.WriteLine(ex.Message);
                }
            }

            foreach (string interviewer in interviewers)
            {
                SelectListItem interviewerListItem = new SelectListItem()
                {
                    Text  = interviewer,
                    Value = interviewer
                };
                DetailSearchCriteria.InterviewerList.Add(interviewerListItem);
            }

            foreach (uas_Group group in groups)
            {
                SelectListItem groupListItem = new SelectListItem()
                {
                    Text  = group.GroupName,
                    Value = group.GroupID.ToString()
                };
                DetailSearchCriteria.GroupList.Add(groupListItem);
            }

            bool admin = false;

            foreach (int grp in SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups)
            {
                if (grp == 0)
                {
                    admin = true;
                    break;
                }
            }

            foreach (uas_Enterprise ent in ents)
            {
                SelectListItem entListItem = new SelectListItem()
                {
                    Text  = ent.EnterpriseName,
                    Value = ent.EnterpriseID.ToString()
                };

                // if user is enterprise admin, show enterprise
                if (SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups[0] == 0 || admin)
                {
                    DetailSearchCriteria.EnterpriseList.Add(entListItem);
                }
            }

            // add patterns
            if (!SessionHelper.IsVentureMode && patternsForEnterprise.ConfigValue.Contains("1"))
            {
                DetailSearchCriteria.PatternList.Add(new SelectListItem()
                {
                    Value = "1",
                    Text  = "1. Important To, Important For Utilization Check"
                });
            }
            if (!SessionHelper.IsVentureMode && patternsForEnterprise.ConfigValue.Contains("2"))
            {
                DetailSearchCriteria.PatternList.Add(new SelectListItem()
                {
                    Value = "2",
                    Text  = "2. Learning Job Skills Typical Person Standard Check"
                });
            }

            if (!SessionHelper.IsVentureMode && patternsForEnterprise.ConfigValue.Contains("3"))
            {
                DetailSearchCriteria.PatternList.Add(new SelectListItem()
                {
                    Value = "3",
                    Text  = "3. Transportation Consistency Check"
                });
            }

            if (!SessionHelper.IsVentureMode && patternsForEnterprise.ConfigValue.Contains("4"))
            {
                DetailSearchCriteria.PatternList.Add(new SelectListItem()
                {
                    Value = "4",
                    Text  = "4. Relationship \"Typical Person Standard\" Check"
                });
            }

            if (!SessionHelper.IsVentureMode && patternsForEnterprise.ConfigValue.Contains("5"))
            {
                DetailSearchCriteria.PatternList.Add(new SelectListItem()
                {
                    Value = "5",
                    Text  = "5. Sexual Aggression Community Safety Consistency Check"
                });
            }

            if (!SessionHelper.IsVentureMode && patternsForEnterprise.ConfigValue.Contains("6"))
            {
                DetailSearchCriteria.PatternList.Add(new SelectListItem()
                {
                    Value = "6",
                    Text  = "6. Ambulation Consistency Check"
                });
            }
        }
Beispiel #7
0
        public static void TransformAndAppendResponseNodesToXML(
            XmlNode appendTo, XmlDocument doc, DefResponseElement rspElement, int formResultId, IFormsRepository formsRepo)
        {
            string elementContent = null;

            //super-special case for Enrollment_Type, which is based on the formStatus, rather than responses
            if (rspElement.tagName == "Enrollment_Type")
            {
                #region check the formResult.formStatus field to determin enrollment type

                def_FormResults  fr           = formsRepo.GetFormResultById(formResultId);
                def_StatusMaster statusMaster = formsRepo.GetStatusMasterByFormId(fr.formId);
                def_StatusDetail statusDetail = formsRepo.GetStatusDetailBySortOrder(statusMaster.statusMasterId, fr.formStatus);
                switch (statusDetail.identifier)
                {
                case "NEEDS_INFORMATION":
                    elementContent = "2";
                    break;

                case "APPROVED":
                    elementContent = "2";
                    break;

                default:
                    elementContent = "1";
                    break;
                }

                #endregion
            }

            if (rspElement.tagName == "Email")
            {
                #region check uas tables for email
                using (UASEntities context = Data.Concrete.DataContext.getUasDbContext())
                {
                    def_FormResults fr   = formsRepo.GetFormResultById(formResultId);
                    var             data = from ue in context.uas_UserEmail
                                           where ue.UserID == fr.subject &&
                                           ue.EmailAddress != null &&
                                           ue.MayContact
                                           orderby ue.SortOrder
                                           select ue.EmailAddress;
                    elementContent = data.FirstOrDefault();
                }
                #endregion
            }

            if (rspElement.tagName == "Mailing_Address" || rspElement.tagName == "Mailing_City" ||
                rspElement.tagName == "Mailing_State" || rspElement.tagName == "Mailing_Zip")
            {
                def_ResponseVariables rv = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, "ADAP_C2_SameAsMailing");
                if (rv.rspInt != null && rv.rspInt == 1)
                {
                    return;
                }
            }

            //assign a special-case transformation value if applicable
            if (elementContent == null)
            {
                elementContent = RamsellTransformations.GetExportValueForRamsellTag(rspElement.tagName, formResultId, formsRepo);
            }

            //if elementContent has been assigned a non-null value,
            //it must have been assigned to handle a one-off special case (above),
            //so append one node with elementContent and terminate this function
            if (elementContent != null)
            {
                AppendContentNodeToXML(appendTo, doc, rspElement.tagName, elementContent);
                return;
            }

            #region normal case: append an xml node for each associated itemvariable identifier in ramsellIdentifierMap

            List <string> ivIdentList = GetItemVariableIdentifiersForRamsellTagName(rspElement.tagName);
            foreach (string ivIdent in ivIdentList)
            {
                def_ResponseVariables rv = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, ivIdent);
                if ((rv != null) && !String.IsNullOrWhiteSpace(rv.rspValue))
                {
                    elementContent = GetFormattedResponse(rv, rspElement.xmlType, formsRepo);
                }
                else
                {
                    GetDefaultValue(rspElement.xmlType);  // to pass validation
                }

                //if there are multiple itemVariables, assume this is one out of a set of checkboxes
                //in which case zeroes represent unchecked checkboxes which should be ignored
                if ((elementContent == "0") && (ivIdentList.Count > 1))
                {
                    continue;
                }

                // if no output and the tag is optional, don't write it out
                //   *** For some reason Ramsell system doesn't seem process empty tags or recognize as valid
                //   *** Even though they pass XML / XSD validation
                if (String.IsNullOrWhiteSpace(elementContent) && rspElement.minOccurs.Equals(0.0m))
                {
                    continue;
                }

                AppendContentNodeToXML(appendTo, doc, rspElement.tagName, elementContent);
            }

            #endregion
        }
        /// <summary>
        /// Update lookup detail and lookup text records in the database (add them, update existing not currently supported --LK 11/4/2015)
        /// </summary>
        /// <param name="dataValues"></param>
        /// <param name="formsRepo"></param>
        private void UpdateLookups(int enterpriseId, string[] dataValues, IFormsRepository formsRepo)
        {
            int lookupDetailId;

            bool newDetail = false;

            def_LookupMaster lookupMaster = formsRepo.GetLookupMastersByLookupCode("ADAP_CLINIC");

            if (lookupMaster == null)
            {
                throw new Exception("Cannot find lookup master: code ADAP_CLINIC");
            }

            def_LookupDetail lookupDetail = null;

            // Display Choice (required)
            if (String.IsNullOrEmpty(dataValues[1]))
            {
                throw new Exception("Display Text is required field.");
            }

            // Display Order (required)
            if (String.IsNullOrEmpty(dataValues[0]))
            {
                throw new Exception("Display Order is required field. Missing for: " + dataValues[1]);
            }



            short langId = 0;

            // Check that language ID is valid (or empty)
            if (!Int16.TryParse(dataValues[2], out langId) || (langId != 1 && langId != 2))
            {
                throw new Exception("Invalid language ID for: " + dataValues[1]);
            }

            // Try to find lookup detail by ID
            if (Int32.TryParse(dataValues[6], out lookupDetailId))
            {
                lookupDetail = formsRepo.GetLookupDetailById(lookupDetailId);
            }

            if (lookupDetail == null && !String.IsNullOrEmpty(dataValues[5])) // find by data value
            {
                lookupDetail = formsRepo.GetLookupDetailByEnterpriseMasterAndDataValue(enterpriseId, lookupMaster.lookupMasterId, dataValues[5]);
            }

            if (lookupDetail == null && !String.IsNullOrEmpty(dataValues[1])) // find by display text and language
            {
                def_LookupText tempLookupText = formsRepo.GetLookupTextByDisplayTextEnterpriseIdMasterLang(dataValues[1], enterpriseId, lookupMaster.lookupMasterId, langId);

                if (tempLookupText != null)
                {
                    lookupDetail = formsRepo.GetLookupDetailById(tempLookupText.lookupDetailId);
                }
            }

            if (lookupDetail == null)
            {
                lookupDetail = new def_LookupDetail();
                newDetail    = true;
            }

            lookupDetail.lookupMasterId = lookupMaster.lookupMasterId;


            // Set detail's display order
            int dispOrder = 0;

            if (!Int32.TryParse(dataValues[0], out dispOrder))
            {
                throw new Exception("Display Order is not valid for: " + dataValues[1]);
            }
            else
            {
                lookupDetail.displayOrder = dispOrder;
            }

            // Set detail's status flag
            if (String.IsNullOrEmpty(dataValues[4]))
            {
                lookupDetail.StatusFlag = "A";
            }
            else if (dataValues[4].ToUpper() == "A" || dataValues[4].ToLower() == "active")
            {
                lookupDetail.StatusFlag = "A";
            }
            else if (dataValues[4].ToUpper() == "I" || dataValues[4].ToLower() == "inactive")
            {
                lookupDetail.StatusFlag = "I";
            }
            else
            {
                throw new Exception("Invalid value in Status Flag field for " + dataValues[1]);
            }


            // Set detail's data value (if data value field in spread sheet is blank, use display choice field instead (which is required))
            string dataValue = dataValues[5];

            if (String.IsNullOrEmpty(dataValues[5]))
            {
                dataValue = dataValues[1];
            }

            lookupDetail.dataValue = dataValue;

            lookupDetail.EnterpriseID = enterpriseId;

            int groupId = 0;

            if (Int32.TryParse(dataValues[3], out groupId))
            {
                lookupDetail.GroupID = groupId;

                UASEntities uasEntities = new UASEntities();

                uas_Group group = uasEntities.uas_Group.Where(g => g.GroupID == groupId && g.EnterpriseID == enterpriseId).FirstOrDefault();

                if (group == null)
                {
                    throw new Exception("Group with ID " + groupId + " does not exist for " + dataValues[1]);
                }
            }
            else
            {
                throw new Exception("Missing group ID for " + dataValues[1]);
            }

            if (newDetail)
            {
                // Add new lookup detail
                formsRepo.AddLookupDetail(lookupDetail);
            }
            else
            {
                // Update existing lookup detail
                formsRepo.SaveLookupDetail(lookupDetail);
            }

            def_LookupText lookupText = null;

            bool newLookupText = false;


            lookupText = formsRepo.GetLookupTextsByLookupDetailLanguage(lookupDetail.lookupDetailId, langId).FirstOrDefault();

            if (lookupText == null)
            {
                lookupText    = new def_LookupText();
                newLookupText = true;
            }

            // Set Display Choice (required)
            lookupText.displayText = dataValues[1];

            // Set Language
            if (String.IsNullOrEmpty(dataValues[2]))
            {
                throw new Exception("Language ID is a required field.");
            }
            else
            {
                // Language ID is either 1 (English) or 2 (Spanish), so use value
                lookupText.langId = langId;
            }
            // Set lookup detail ID to be for the associated lookup detail (either just saved/added)
            lookupText.lookupDetailId = lookupDetail.lookupDetailId;

            if (newLookupText)
            {
                // Add new lookup text
                formsRepo.AddLookupText(lookupText);
            }
            else
            {
                // Update the lookup text
                formsRepo.SaveLookupText(lookupText);
            }
        }