コード例 #1
0
        public ActionResult Create(HttpPostedFileBase file, [Bind(Include = "Id,Username,Titel,Description,Image,Date,Place")] Moments.Models.Moments moments)
        {
            ViewBag.MetadataControll = db.Metadata.ToList();
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path     = Path.Combine(Server.MapPath("~/Images/"), fileName);
                moments.Image = "/Images/" + fileName;
                file.SaveAs(path);
            }
            else
            {
                return(Redirect("/Moments/Create")); //If there is no file you will be redirected to the same page
            }

            if (ModelState.IsValid)
            {
                db.Moments.Add(moments);
                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(Redirect("/Moments/"));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,Username,Password,Email")] Login login)
        {
            if (ModelState.IsValid)
            {
                db.Login.Add(login);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(login));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "Id,Country")] Place place)
        {
            if (ModelState.IsValid)
            {
                db.Place.Add(place);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(place));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "Id,DC_Title,DC_Description,DC_Creator,DC_Publisher,DC_Keywords,DC_Type")] Metadata metadata)
        {
            if (ModelState.IsValid)
            {
                db.Metadata.Add(metadata);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DC_Creator = new SelectList(db.Login, "Id", "Username", metadata.DC_Creator);
            return(View(metadata));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Id,Username,Titel,Description,Image,Date,Place")] Moments.Models.Moments moments)
        {
            if (ModelState.IsValid)
            {
                db.Moments.Add(moments);
                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));
        }
コード例 #6
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);
        }