Esempio n. 1
0
 public ActionResult Index()
 {
     using (var db = new AdminParamEntities())
     {
         return View(db.AdminParams.ToList());
     }
 }
Esempio n. 2
0
 public ActionResult Edit(int id)
 {
     using (var db = new AdminParamEntities())
     {
         return View(db.AdminParams.Find(id));
     }
 }
Esempio n. 3
0
 public ActionResult Edit(int id, AdminParam param)
 {
     try
     {
         using (var db = new AdminParamEntities())
         {
             db.Entry(param).State = EntityState.Modified;
             db.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch
     {
         return View();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Простенький метод отправки
        /// </summary>
        /// <param name="message"></param>
        public static void SendMail(MailMessage message)
        {
            if (message == null) return;
            using (var db = new AdminParamEntities())
            {
                var mailclient = new SmtpClient
                                     {
                                         Host = db.AdminParams.First(p => p.Name == "smtpserver").Value,
                                         Port = Convert.ToInt32(db.AdminParams.First(p => p.Name == "smtpport").Value),
                                         EnableSsl = Convert.ToBoolean(db.AdminParams.First(p => p.Name == "smtpssl").Value),
                                         Credentials = new System.Net.NetworkCredential(
                                             db.AdminParams.First(p => p.Name == "smtplogin").Value,
                                             db.AdminParams.First(p => p.Name == "smtppass").Value)
                                     };

                mailclient.Send(message);
            }
        }
Esempio n. 5
0
        public ActionResult ContactUs(ContacFormViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var model = new FeedBack();
                TryUpdateModel(model);
                model.CreateDate = DateTime.Now;

                using (var context = new FeedBackEntities())
                {
                    context.FeedBacks.Add(model);
                    context.SaveChanges();
                }

                new Thread(() =>
                {
                    try
                    {
                        MailMessage message;
                        using (var db = new AdminParamEntities())
                        {
                            message = new MailMessage(viewModel.Email,
                                                      db.AdminParams.First(p => p.Name == "adminemail").Value,
                                                      db.AdminParams.First(p => p.Name == "feedbacksubject").Value,
                                                      string.Format("From: {0}\nEmail: {1}\nDate: {2}\n\n{3}",
                                                                    model.FullName, model.Email, model.CreateDate, model.Message)
                                                       );
                        }
                        EmailService.SendMail(message);
                    }
                    catch (Exception)
                    {
                        //todo: Обработать ошибку отправки почты
                    }

                }).Start();

                return RedirectToAction("Index");
            }
            return View(viewModel);
        }