示例#1
0
 public ActionResult Favorites(string city_name, string country_code)
 {
     using (WeatherDataEntities dc = new WeatherDataEntities())
     {
         var favdb = dc.favourites.ToList <favourite>();
         var email = Session["LoggedEmail"];
         var pass  = Session["LoggedUsername"];
         int favCount;
         if (System.Web.HttpContext.Current.Session["LoggedUsername"] != null)
         {
             favCount = favdb.Where(fv => fv.Email == email.ToString() && city_name.Equals(fv.CityName)).Count();
             if (favCount > 0)
             {
                 string fv = "Favourite city already added..!";
                 return(Json(fv, JsonRequestBehavior.AllowGet));
             }
             else
             {
                 favourite fav = new favourite();
                 fav.CityName = city_name;
                 fav.Email    = email.ToString();
                 fav.Zipcode  = country_code;
                 dc.favourites.Add(fav);
                 dc.SaveChanges();
                 string fv = "Favourite city saved successfully";
                 return(Json(fv, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
         }
     }
 }
示例#2
0
        public ActionResult Delete(string city)
        {
            using (WeatherDataEntities dc = new WeatherDataEntities())

                if (ModelState.IsValid) // this is check validity
                {
                    dc.favourites.Remove(dc.favourites.Where(c => c.CityName.ToUpper() == city.ToUpper()).FirstOrDefault());
                    dc.SaveChanges();
                }

            string fv = "City Removed";

            return(Json(fv, JsonRequestBehavior.AllowGet));
        }
 public ActionResult EditFields(string Phone, string Address1, string Address2, string City, string State, string Country, string Zipcode)
 {
     using (WeatherDataEntities dc = new WeatherDataEntities())
         if (ModelState.IsValid) // this is check validity
         {
             SqlConnection con = new SqlConnection(@"data source = indradb.database.windows.net; initial catalog = WeatherData; persist security info = True; user id = dbadmin; password = Admin123;");
             // SqlConnection con = new SqlConnection(@"Data Source=192.168.10.156\SQL2008;initial catalog=WeatherData;persist security info=True;user id=sa;password=admin@2008;");
             con.Open();
             SqlCommand cmd = new SqlCommand("Update register set Phone = '" + Phone + "',Address1= '" + Address1 + "',Address2= '" + Address2 + "',City= '" + City + "',State= '" + State + "',Country= '" + Country + "',Zipcode= '" + Zipcode + "'where Email='" + Session["LoggedEmail"].ToString() + "'", con);
             cmd.ExecuteNonQuery();
             con.Close();
         }
     TempData["editComplete"] = "Data Saved";
     return(RedirectToAction("MyHome", "SignInCon"));
 }
        public ActionResult ForgotPassword(string email)
        {
            if (ModelState.IsValid)
            {
                using (WeatherDataEntities dc = new WeatherDataEntities())
                {
                    var v = dc.registers.Where(a => a.Email.Equals(email)).FirstOrDefault();
                    if (v != null)
                    {
                        string strNewPassword = Membership.GeneratePassword(10, 0).ToString();

                        // SqlConnection con = new SqlConnection(@"Data Source=192.168.10.156\SQL2008;initial catalog=WeatherData;persist security info=True;user id=sa;password=admin@2008;");
                        SqlConnection con = new SqlConnection(@"data source = indradb.database.windows.net; initial catalog = WeatherData; persist security info = True; user id = dbadmin; password = Admin123;");
                        con.Open();
                        SqlCommand cmd = new SqlCommand("Update register set Password = '******'where Email='" + email + "'", con);
                        cmd.ExecuteNonQuery();
                        con.Close();
                        // to send the random password in email

                        MailMessage mail = new MailMessage();
                        mail.To.Add(email);
                        mail.From       = new MailAddress("*****@*****.**");
                        mail.Subject    = "DoNotReply";
                        mail.Body       = "<b>Hello..!</b> <br>Kindly use the given password and login to you account and enjoy your weather journey.<br> Your New Password is <b>" + strNewPassword + "</b>";
                        mail.IsBodyHtml = true;

                        SmtpClient smtp = new SmtpClient();
                        smtp.Host                  = "smtp.gmail.com";
                        smtp.Port                  = 587;
                        smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        smtp.UseDefaultCredentials = false;
                        smtp.EnableSsl             = true;
                        ICredentialsByHost credentials = new NetworkCredential("*****@*****.**", "fabme@21");
                        smtp.Credentials = credentials;
                        smtp.Send(mail);
                        TempData["Success"] = "Mail Sent!";
                        return(RedirectToAction("SignIn", "SignInCon"));
                    }
                    else
                    {
                        TempData["Fail"] = "It Seems you have not yet registered. Please Register with us..!";
                        return(RedirectToAction("SignIn", "SignInCon"));
                    }
                }
            }
            return(View());
        }
示例#5
0
        public ActionResult Index(string password)
        {
            using (WeatherDataEntities dc = new WeatherDataEntities())

                if (ModelState.IsValid) // this is check validity
                {
                    if ((password != null))
                    {
                        SqlConnection con = new SqlConnection(@"data source = indradb.database.windows.net; initial catalog = WeatherData; persist security info = True; user id = dbadmin; password = Admin123;");
                        //SqlConnection con = new SqlConnection(@"Data Source=192.168.10.156\SQL2008;initial catalog=WeatherData;persist security info=True;user id=sa;password=admin@2008;");
                        con.Open();
                        SqlCommand cmd = new SqlCommand("Update register set Password = '******'where Email='" + Session["LoggedEmail"].ToString() + "'", con);
                        cmd.ExecuteNonQuery();
                        con.Close();
                        TempData["editComplete"] = "Password Changed";
                    }
                }
            return(RedirectToAction("MyHome", "SignInCon"));
        }
        public ActionResult EditFields()
        {
            var    email       = Session["LoggedEmail"];
            var    pass        = Session["LoggedUsername"];
            String emailofuser = email.ToString();

            using (WeatherDataEntities dc = new WeatherDataEntities())
            {
                if (email == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                register register = dc.registers.Find(emailofuser);
                if (register == null)
                {
                    return(HttpNotFound());
                }
                return(View(register));
            }
        }
 public ActionResult SignIn(register u)
 {
     if (ModelState.IsValid) // this is check validity
     {
         using (WeatherDataEntities dc = new WeatherDataEntities())
         {
             var v = dc.registers.Where(a => a.Email.Equals(u.Email) && a.Password.Equals(u.Password)).FirstOrDefault();
             if (v != null)
             {
                 Session["LoggedEmail"]    = v.Email.ToString();
                 Session["LoggedUsername"] = v.UserName.ToString();
                 TempData["Success"]       = "You're now Signed in";
                 return(RedirectToAction("MyHome", "SignInCon"));
             }
             else
             {
                 TempData["Fail"] = "Invalid Email or password..!";
                 return(RedirectToAction("SignIn", "SignInCon"));
             }
         }
     }
     return(View(u));
 }