context: using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Xml.Serialization;
  using CmsData;
  using CmsData.Registration;
  using UtilityExtensions;
  using System.Text.RegularExpressions;
  using CmsData.Codes;
  
  namespace CmsWeb.Models
  {
      public partial class OnlineRegModel
      {
          public static Organization CreateAccountOrg()
          {
              var settings = HttpContext.Current.Items["RegSettings"] as Dictionary<int, Settings>;
              if (settings == null)
              {
                  settings = new Dictionary<int, Settings>();
                  HttpContext.Current.Items.Add("RegSettings", settings);
              }
              var o = new Organization { OrganizationId = Util.CreateAccountCode, OrganizationName = "My Data" };
              o.RegistrationTypeId = RegistrationTypeCode.CreateAccount;
              if (!settings.ContainsKey(Util.CreateAccountCode))
                  settings.Add(Util.CreateAccountCode, ParseSetting("AllowOnlyOne: true", Util.CreateAccountCode));
              return o;
          }
  
          private Dictionary<int, Settings> _settings;
  
          public Dictionary<int, Settings> settings
          {
              get
              {
                  if (_settings == null)
                      _settings = HttpContext.Current.Items["RegSettings"] as Dictionary<int, Settings>;
                  if (_settings == null)
                  {
                      ParseSettings();
                      _settings = HttpContext.Current.Items["RegSettings"] as Dictionary<int, Settings>;
                  }
                  return _settings;
              }
          }
  
          public bool DisplayLogin()
          {
              return (List.Count == 0 && !UserPeopleId.HasValue && nologin == false);
          }
  
          public string LoginName
          {
              get
              {
                  if (user != null)
                      return user.Name;
                  return "anonymous";
              }
          }
  
          public string MeetingTime
          {
              get { return meeting().MeetingDate.ToString2("f"); }
          }
  
          public OnlineRegPersonModel last
          {
              get
              {
                  if (_list.Count > 0)
                      return _list[_list.Count - 1];
                  return null;
              }
          }
  
          public string qtesting
          {
              get { return testing == true ? "?testing=true" : ""; }
          }
  
          public bool IsCreateAccount()
          {
              if (org != null)
                  return org.RegistrationTypeId == RegistrationTypeCode.CreateAccount;
              return false;
          }
  
          public bool IsEnded()
          {
              return IsEnded(masterorg) || IsEnded(org);
          }
  
          private bool IsEnded(Organization o)
          {
              if (o != null)
                  return o.ClassFilled == true;
              return false;
          }
  
          private bool Filled(Organization o)
          {
              if (o != null)
                  if ((o.ClassFilled ?? false) || (o.Limit > 0 && o.Limit <= o.RegLimitCount(DbUtil.Db)))
                      return true;
              return false;
          }
  
          public string Filled()
          {
              return Filled(masterorg) || Filled(org) ? "registration is full" : "";
          }
  
          public bool NotAvailable()
          {
              if (SupportMissionTrip)
                  return false;
              var dt = DateTime.Now;
              var dt1 = DateTime.Parse("1/1/1900");
              var dt2 = DateTime.Parse("1/1/2200");
              if (masterorgid.HasValue)
                  return masterorg.RegistrationClosed == true
                         || masterorg.OrganizationStatusId == OrgStatusCode.Inactive
                         || dt < (masterorg.RegStart ?? dt1)
                         || (dt > (masterorg.RegEnd ?? dt2) && !GoerSupporterId.HasValue);
              return org.RegistrationClosed == true
                     || org.OrganizationStatusId == OrgStatusCode.Inactive
                     || dt < (org.RegStart ?? dt1)
                     || (dt > (org.RegEnd ?? dt2) && !GoerSupporterId.HasValue);
          }
  
          public bool UserSelectsOrganization()
          {
              return masterorgid.HasValue && masterorg.RegistrationTypeId == RegistrationTypeCode.UserSelectsOrganization2;
          }
  
          public bool OnlyOneAllowed()
          { 
              if (org != null)
              {
                  var setting = settings[org.OrganizationId];
                  return org.RegistrationTypeId == RegistrationTypeCode.ChooseVolunteerTimes
                         || org.RegistrationTypeId == RegistrationTypeCode.CreateAccount
                         || org.IsMissionTrip == true
                         || setting.AllowOnlyOne 
                         || setting.AskVisible("AskTickets")
                         || ChoosingSlots() 
                         || OnlineGiving() 
                         || ManageGiving()
                         || SupportMissionTrip;
              }
              if (settings != null)
              {
                  var q = from o in settings.Values
                          where o.AllowOnlyOne || o.AskVisible("AskTickets")
                          select o;
                  return q.Any();
              }
              return false;
          }
  
          public bool RecordFamilyAttendance()
          {
              return org != null && org.RegistrationTypeId == RegistrationTypeCode.RecordFamilyAttendance;
          }
  
          public bool ChoosingSlots()
          {
              if (org != null)
                  return org.RegistrationTypeId == RegistrationTypeCode.ChooseVolunteerTimes;
              return false;
          }
  
          public bool ManagingSubscriptions()
          {
              return masterorgid.HasValue && masterorg.RegistrationTypeId == RegistrationTypeCode.ManageSubscriptions2;
          }
  
          public bool OnlinePledge()
          {
              if (org != null)
                  return org.RegistrationTypeId == RegistrationTypeCode.OnlinePledge;
              return false;
          }
  
          public bool ManageGiving()
          {
              if (org != null)
                  return org.RegistrationTypeId == RegistrationTypeCode.ManageGiving;
              return false;
          }
  
          public bool OnlineGiving()
          {
              if (org != null)
                  return org.RegistrationTypeId == RegistrationTypeCode.OnlineGiving;
              return false;
          }
  
          public bool NoCreditCardsAllowed()
          {
              if (org != null)
  
gt:                 return org.NoCreditCards == true;