예제 #1
0
        public ActionResult EditEMailSettings(EMailSettingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                ASConfiguration config = new ASConfiguration();
                config.SMTPDefaultCredentials = model.DefaultCredentials;
                config.SMTPEnableSsl          = model.EnableSsl;
                config.SMTPFromAddress        = model.FromAddress;
                config.SMTPFromDisplayName    = model.FromDisplayName;
                config.SMTPHost     = model.Host;
                config.SMTPName     = model.Name;
                config.SMTPPassword = model.Password;
                config.SMTPPort     = model.Port;
                config.SMTPTimeOut  = model.TimeOut;
                config.SMTPUserName = model.UserName;

                string result = _configurationService.CanConnectSMTPServer(config);

                if (!string.IsNullOrEmpty(result))
                {
                    throw new ASException(result);
                }

                SettingValue value = (SettingValue)model;

                if (model.Id > 0)
                {
                    SettingValue dbValue = _settingService.GetSettingValueById(model.Id);

                    if (dbValue.IsHiddenFromUser)
                    {
                        throw new ASException(this._resourceManager.GetString("ErrorMessage_UnableToUpdate"));
                    }

                    value.SettingDefinitionID = dbValue.SettingDefinitionID;
                    value.CreatedBy           = dbValue.CreatedBy;
                    value.CreatedOn           = dbValue.CreatedOn;
                    _settingService.UpdateSettingValue(value);

                    TempData["ResultType"]    = MessageType.Success;
                    TempData["ResultMessage"] = this._resourceManager.GetString("Resources.SettingValueUpdateSuccess");
                }
                else
                {
                    value.SettingDefinitionID = _settingService.GetSettingDefinitionByName("EMailSetting").Id;
                    _settingService.AddSettingValue(value);
                    TempData["ResultType"]    = MessageType.Success;
                    TempData["ResultMessage"] = this._resourceManager.GetString("SettingValueUpdateSuccess");
                }
                _cacheService.Clear();

                TempData["ResultModel"] = model;
                return(RedirectToAction("Result", "Shared"));
            }
            catch (ASException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(View(model));
        }