Ejemplo n.º 1
0
 public void Deletar(Models.BL bl)
 {
     using (var contexto = new Context()) {
         contexto.BL.Remove(bl);
         contexto.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public void Adiciona(Models.BL bl)
 {
     using (var context = new Context()) {
         context.BL.Add(bl);
         context.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void Atualiza(Models.BL bl)
 {
     using (var contexto = new Context()) {
         contexto.Entry(bl).State = System.Data.Entity.EntityState.Modified;
         contexto.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public ActionResult Deletar(Models.BL bl)
 {
     DAO.BLDAO dao = new DAO.BLDAO();
     dao.Deletar(bl);
     return(RedirectToAction("/viewBl"));
 }
Ejemplo n.º 5
0
 public ActionResult Editar(Models.BL bl)
 {
     DAO.BLDAO dao = new DAO.BLDAO();
     dao.Atualiza(bl);
     return(RedirectToAction("/viewBl"));
 }
Ejemplo n.º 6
0
 public ActionResult Adiciona(Models.BL bl)
 {
     DAO.BLDAO dao = new DAO.BLDAO();
     dao.Adiciona(bl);
     return(RedirectToAction("/viewBl"));
 }
        public ActionResult SendPassword(FormCollection fc)
        {
            string username = "";
            string usermail = "";

            // Fetch username and mail for user:
            foreach (var user in db.Users.ToList())
            {
                username = user.username;
                usermail = user.mail;
            }

            MailMessage mail = new MailMessage();

            // Mail receiver address:
            mail.To.Add(usermail);
            string sender = ConfigurationManager.AppSettings["MailSender"].ToString();

            // Mail will be sent from:
            mail.From    = new MailAddress(sender, "Webbansvarig för bloggsystem", System.Text.Encoding.UTF8);
            mail.Subject = "Nytt lösenord!";
            // Encode to UTF8 to make sure that Swedish letters are read properly:
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            string newpassword = new Models.BL().randomString();

            mail.Body         = "Ditt nya lösenord: <b>" + newpassword + "</b>";
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml   = true;
            mail.Priority     = MailPriority.High;

            // Send the mail through a specific mail account based on SMTP properties below:
            SmtpClient client = new SmtpClient();
            // Fetch password from webconfig for the used account:
            string password = ConfigurationManager.AppSettings["MailSenderPass"].ToString();
            string port     = ConfigurationManager.AppSettings["MailSenderPort"].ToString();
            string host     = ConfigurationManager.AppSettings["MailSenderHost"].ToString();

            client.Credentials = new System.Net.NetworkCredential(sender, password);
            client.Port        = Convert.ToInt32(port);
            client.Host        = host;
            client.EnableSsl   = true;

            try
            {
                // Catch form input:
                string inputname = fc["userinput"];

                if (username == inputname)
                {
                    // Update user table with new password:
                    new Models.PassThrough().updatePassword(newpassword, username);
                    // Send new password to user mail:
                    client.Send(mail);
                    ViewBag.successmsg = "Ett nytt lösenord har nu skickats till den mejladress som är kopplad till ditt användarnamn!<br>"
                                         + "(Obs! Om lösenordet inte skickats till din inkorg så kontrollera din skräppost.)";
                    return(View());
                }
                else
                {
                    ViewBag.errormsg = "Användarnamnet kunde ej hittas!";
                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.errormsg = e.Message;
                return(View());
            }
        }