Example #1
0
        public ActionResult Email(EmailConfigViewModel model, string selectedMailType)
        {
            if (ModelState.IsValid)
            {
                _emailConfig = WebConfigurationManager.OpenWebConfiguration("~").GetSection("EmailConfig") as EmailConfig;
                _emailConfig.MailType = int.Parse(selectedMailType);
                _emailConfig.MailHost = model.MailHost;
                _emailConfig.EnableSsl = model.EnableSsl;
                _emailConfig.MailPort = model.MailPort;
                _emailConfig.MailUser = model.MailUser;
                _emailConfig.MailPassword = model.MailPassword;
                _emailConfig.MailFrom = model.MailFrom;
                _emailConfig.MailFromName = model.MailFromName;
                _emailConfig.MailSign = model.MailSign;

                _emailConfig.CurrentConfiguration.Save();
                return RedirectToAction("Email");
            }
            return View(model);
        }
Example #2
0
        public ActionResult Email()
        {
            _emailConfig = WebConfigurationManager.OpenWebConfiguration("~").GetSection("EmailConfig") as EmailConfig;
            var model = new EmailConfigViewModel();

            ViewBag.mailType = new SelectList(Enum.GetValues(typeof(MailType)).Cast<MailType>()
                .Select(x => new SelectListItem()
                {
                    Text = x.ToString(),
                    Value = ((int)x).ToString()
                }).ToList(), "Value", "Text")
            .Select(y => new SelectListItem()
            {
                Selected = (int)_emailConfig.MailType == int.Parse(y.Value),
                Text = y.Text,
                Value = y.Value
            });

            model.MailHost = _emailConfig.MailHost;
            model.EnableSsl = _emailConfig.EnableSsl;
            model.MailPort = _emailConfig.MailPort;
            model.MailUser = _emailConfig.MailUser;
            model.MailPassword = _emailConfig.MailPassword;
            model.MailFrom = _emailConfig.MailFrom;
            model.MailFromName = _emailConfig.MailFromName;
            model.MailSign = _emailConfig.MailSign;

            return View(model);
        }