コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,Country")] Place place)
 {
     if (ModelState.IsValid)
     {
         db.Entry(place).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(place));
 }
コード例 #2
0
 public ActionResult PasswordSent([Bind(Include = "Id,Username,Password,Email")] Login login)
 {
     ViewBag.MetadataControll = db.Metadata.ToList();
     if (ModelState.IsValid)
     {
         db.Entry(login).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(login));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,DC_Title,DC_Description,DC_Creator,DC_Publisher,DC_Keywords,DC_Type")] Metadata metadata)
 {
     if (ModelState.IsValid)
     {
         db.Entry(metadata).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DC_Creator = new SelectList(db.Login, "Id", "Username", metadata.DC_Creator);
     return(View(metadata));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "Id,Username,Titel,Description,Image,Date,Place")] Moments.Models.Moments moments)
 {
     if (ModelState.IsValid)
     {
         db.Entry(moments).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Username = new SelectList(db.Login, "Id", "Username", moments.Username);
     ViewBag.Place    = new SelectList(db.Place, "Id", "Country", moments.Place);
     return(View(moments));
 }
コード例 #5
0
        private void sendEmail(string sendTo)
        {
            SmtpClient client = new SmtpClient();

            client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "momentsapp");
            client.Port        = 587;
            client.Host        = "smtp.gmail.com";
            client.EnableSsl   = true;
            MailMessage mail = new MailMessage();

            //Setting From , To and CC
            mail.From = new MailAddress("*****@*****.**", "Moments Application");
            mail.To.Add(new MailAddress(sendTo));
            mail.Subject = "Reset Password";
            string newPass = createNewPassword();

            mail.Body = "Hey, we heard that you lost your password, but no worries! We have a new one for you right here: " + newPass;

            //kryptering av det nya lösenordet till md5-lösenord för att göra applikationen lite säkrare
            var loginList = db.Login.ToList();

            foreach (Login log in loginList)
            {
                string password = FormsAuthentication.HashPasswordForStoringInConfigFile(newPass.Trim(), "md5"); //kryptering

                //change password in database
                var user = new Login()
                {
                    Id = log.Id, Password = password
                };
                using (var db = new MomentsEntities1())
                {
                    db.Login.Attach(user);
                    db.Entry(user).Property(x => x.Password).IsModified = true;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }
            }
            client.Send(mail);
        }