Example #1
0
 public ActionResult Update(FormCollection collection)
 {
     var msg = new GenericMessage();
     using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
     {
         string returnUrl = collection["returnUrl"];
         foreach (var key in collection.AllKeys)
         {
             var settings = SettingsService.Get(key);
             if (settings != null)
             {
                 settings.Value = collection[key];
             }
         }
         try
         {
             unitOfWork.Commit();
             msg.Message = "设置保存成功!";
             msg.MessageType = GenericMessageType.success;
         }
         catch (Exception ex)
         {
             unitOfWork.Rollback();
             LoggingService.Error(ex);
             msg.Message = "设置保存失败!";
             msg.MessageType = GenericMessageType.warning;
         }
         if (string.IsNullOrEmpty(returnUrl))
         {
             returnUrl = Request.UrlReferrer.AbsolutePath;
         }
         TempData[AppConstants.MessageViewBagName] = msg;
         return Redirect(returnUrl);
     }
 }
Example #2
0
 public ActionResult TestEmailSettings(FormCollection collection)
 {
     var msg = new GenericMessage();
     using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
     {
         foreach (var key in collection.AllKeys)
         {
             var settings = SettingsService.Get(key);
             if (settings != null)
             {
                 settings.Value = collection[key];
             }
         }
         try
         {
             unitOfWork.Commit();
             var mail = new Email
             {
                 Subject = string.Format("【{0}】测试邮件", SettingsService.Get()[AppConstants.SiteName].Value),
                 Body = "测试邮件,请勿回复",
                 NameTo = "Hubert",
                 EmailFrom = SettingsService.Get()[AppConstants.NotificationReplyEmail].Value,
                 EmailTo = SettingsService.Get()[AppConstants.NotificationReplyEmail].Value
             };
             _emailService.SendMail(mail);
             msg.Message = "一份测试邮件已经发送到你的通知邮箱中。";
             msg.MessageType = GenericMessageType.success;
             TempData[AppConstants.MessageViewBagName] = msg;
         }
         catch (Exception ex)
         {
             LoggingService.Error(ex);
             msg.Message = "邮件发送失败,请检查你填写的信息是否正确。";
             msg.MessageType = GenericMessageType.warning;
         }
     }
     return RedirectToAction("Email");
 }