예제 #1
0
        public ActionResult DeleteConfirmed(int?id)
        {
            var     db     = new projectdbEntities(); // Öppnar anslutning till databasen.
            Errents errent = db.Errents.Find(id);

            db.Errents.Remove(errent);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "Assigned")] Errents errent)
 {
     if (ModelState.IsValid)
     {
         var db = new projectdbEntities(); // Öppnar anslutning till databasen.
         db.Entry(errent).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Errents"));
     }
     return(View(errent));
 }
예제 #3
0
        public ActionResult saveErrent(Errents model)
        {
            try
            {
                //Sparar ärende i databas.
                projectdbEntities db     = new projectdbEntities();
                Errents           errent = new Errents();
                errent.Name            = model.Name;
                errent.Email           = model.Email;
                errent.ErrentCathegory = model.ErrentCathegory;
                errent.Errent          = model.Errent;
                db.Errents.Add(errent);
                db.SaveChanges();
                int latestErrentId = model.id;


                //Mailar bekräftelse till den sm skickar in ärende.
                var          fromAddress  = new MailAddress(Secret.GetValues("username"), "CMS");
                var          toAddress    = new MailAddress(errent.Email, errent.Name);
                string       fromPassword = Secret.GetValues("password");
                const string subject      = "Vi har mottagit ditt ärende";
                const string body         = "Vi handlägger ditt ärende skyndsamt och återkommer till dig.";

                var smtp = new SmtpClient
                {
                    Host           = "smtp.gmail.com",
                    Port           = 587,
                    EnableSsl      = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials    = new NetworkCredential(fromAddress.Address, fromPassword),
                    Timeout        = 20000
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    smtp.Send(message);
                }
                //S**t på mailfunktion
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index", "create"));
        }
예제 #4
0
        public ActionResult createUser(Users model)
        {
            try
            {
                //Sparar ärende i databas.
                projectdbEntities db   = new projectdbEntities();
                Users             user = new Users();
                user.Username = model.Username;
                user.Password = model.Password;
                user.Email    = model.Email;
                user.AccessId = model.AccessId;
                db.Users.Add(user);
                db.SaveChanges();
                int latestUserId = model.UserId;
            }

            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index", "CreateUser"));
        }