예제 #1
0
        public SettingsModel getServiceSetting(string _username)
        {
            SettingsModel settings = new SettingsModel();
            using (var cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename" +
             "=|DataDirectory|\\Database.mdf; Integrated Security=True"))
            {
                string _sql = @"SELECT TOP 1 [Service], [Email] FROM [dbo].[Settings] " +
                       @"WHERE [Username] = @u";
                var cmd = new SqlCommand(_sql, cn);
                cmd.Parameters
                    .Add(new SqlParameter("@u", SqlDbType.NVarChar))
                    .Value = _username;
                cn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {

                    while (reader.Read())
                    {
                        settings.Email = reader["Email"].ToString();
                        settings.UserName = _username;
                        settings.Service = Convert.ToBoolean(reader["Service"]);
                    }
                }
                reader.Dispose();
                cmd.Dispose();
                cn.Close();
            }
            return settings;
        }
예제 #2
0
        public ActionResult Settings(SettingsModel settings)
        {
            if (User.Identity.IsAuthenticated)
            {
                settings.SaveSettings(User.Identity.Name, settings.Service);
                return View(settings);
            }

            return RedirectToAction("Login", "Account");
        }
예제 #3
0
 public ActionResult Settings()
 {
     if (ModelState.IsValid)
     {
         if (User.Identity.IsAuthenticated)
         {
             SettingsModel settings = new SettingsModel();
             settings = settings.getServiceSetting(User.Identity.Name);
             return View(settings);
         }
     }
     return View();
 }