public static LodgeSecretary.Models.Lodge GetLodge(int lodgeId)
 {
     var lodge = new LodgeSecretary.Models.Lodge();
     try
     {
         using (var connection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["MasonMaster"].ConnectionString))
         {
             connection.Open();
             using (var command = connection.CreateCommand())
             {
                 command.CommandText = "Select * from Lodge where LodgeId=" + lodgeId;
                 var reader = command.ExecuteReader();
                 if (reader.HasRows)
                 {
                     reader.Read();
                     lodge = ReadLodgeRow(reader);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         lodge =new Models.Lodge() { LodgeName = "ERROR: "+ ex.Message };
     }
     return lodge;
 }
 private static Models.Lodge ReadLodgeRow(System.Data.SqlClient.SqlDataReader reader)
 {
     var lodge = new Models.Lodge();
     lodge.LodgeId = (int)reader["LodgeId"];
     lodge.LodgeName = reader["LodgeName"].ToString();
     lodge.LodgeNumber = reader["LodgeNumber"].ToString();
     lodge.District = reader["District"].ToString();
     lodge.CharterState = reader["CharterState"].ToString();
     lodge.DateChartered = DateTime.Parse(reader["DateChartered"].ToString());
     lodge.LodgeTypeRef = reader["LodgeTypeRef"].ToString();
     lodge.Website = reader["Website"].ToString();
     lodge.Email = reader["Email"].ToString();
     lodge.MonthlyMeeting = reader["MonthlyMeeting"].ToString();
     lodge.StreetAddress = reader["StreetAddress"].ToString();
     lodge.MailAddress = reader["MailAddress"].ToString();
     lodge.MainPhone = reader["MainPhone"].ToString();
     lodge.City = reader["City"].ToString();
     lodge.Zip = reader["Zip"].ToString();
     lodge.DatabaseName = reader["DatabaseName"].ToString();
     return lodge;
 }
 public ActionResult Register(RegisterModel registerModel)
 {
     //WebSecurity.Login(model.UserName, model.Pass word);
     //WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
     if (registerModel.Password != registerModel.ConfirmPassword)
     {
         ModelState.AddModelError("", "Passwords do not match");
     }
     string databaseName = "SampleLodge.xml";
     string success = "ono";
     ActionResult rtn = RedirectToAction("Index", "Home");
     if (ModelState.IsValid)
     {
         try
         {
             if (Request.Form["submitButton"] == "Register and Create a New Lodge")
             {
                 rtn = RedirectToAction("LodgeCreate", "Admin");
                 databaseName = "Add New";
                 success = "ok";
             }
             if (Request.Form["submitButton"] == "Register and log into Sample Lodge")
             {
                 registerModel.LodgeId = MasonMasterData.GetSampleLodgeId();
                 if (registerModel.LodgeId == 0)
                 {
                     var sampleLodge = new Models.Lodge() { LodgeId = 0, LodgeName = "Sample Lodge", IsSample = true, DateChartered = DateTime.Today, DatabaseName = "SampleLodge.xml" };
                     registerModel.LodgeId = MasonMasterData.AddEditLodge(sampleLodge);
                     if (registerModel.LodgeId == 0)
                         success = "Failed to create Sample Lodge";
                     else
                     {
                         success = LodgeDataXml.CreateNewLodgeXmlFile(Server.MapPath("\\App_Data\\") + "SampleLodge.xml");
                     }
                 }
                 else
                     success = "ok";
             }
             if (Request.Form["submitButton"] == "Log In to an Existing Lodge")
             {
                 if (registerModel.MasonId == 0)
                     success = "Mason Number is required";
                 else
                 {
                     // lookup Member
                     databaseName = MasonMasterData.GetLodge(registerModel.LodgeId.Value).DatabaseName;
                     string lodgeFileName = Server.MapPath("\\App_Data\\") + databaseName;
                     var memberInfo = MemberDataXml.GetMember(registerModel.MasonId.Value, lodgeFileName);
                     if (memberInfo == null)
                         success = "Member Information Not Found";
                     else
                     {
                         rtn = RedirectToAction("index", "Home");
                         success = "ok";
                     }
                 }
             }
         }
         catch (Exception e)
         {
             success = e.Message;
         }
         if (success == "ok")
         {
             try
             {
                 FormsAuthentication.SetAuthCookie(registerModel.UserName, false);
                 UserProfile userProfile = new UserProfile();
                 userProfile.UserName = registerModel.UserName;
                 userProfile.LodgeId = registerModel.LodgeId.Value;
                 userProfile.FullName = registerModel.FullName;
                 userProfile.Password = registerModel.Password;
                 //userProfile.DatabaseName = databaseName;
                 success = MasonMasterData.CreateUserProfile(userProfile);
                 success = App_Code.CustomSecurityProvider.Login(registerModel.UserName, registerModel.Password, false);
             }
             catch (Exception ex) { success = ex.Message; }
         }
     }
     else
     {
         ViewBag.LodgeList = GetLodgeList();
         rtn = View(registerModel);
     }
     if (success != "ok")
     {
         ViewBag.LodgeList = GetLodgeList();
         ModelState.AddModelError("", success);
         RedirectToAction("Register", registerModel);
     }
     return rtn;
 }