コード例 #1
0
 public static void UpateModel(ref SMTPSettingsDataStore source, NewSMTPRequest target)
 {
     source.Company   = target.Company;
     source.FromEmail = target.FromEmail;
     source.HostName  = target.HostName;
     source.Password  = target.Password;
     source.Port      = target.Port;
     source.Username  = target.Username;
 }
コード例 #2
0
        public static SMTPSettingsDataStore ToModel(this NewSMTPRequest target)
        {
            var source = new SMTPSettingsDataStore();

            source.Company   = target.Company;
            source.FromEmail = target.FromEmail;
            source.HostName  = target.HostName;
            source.Password  = target.Password;
            source.Port      = target.Port;
            source.Username  = target.Username;
            return(source);
        }
コード例 #3
0
        public virtual Task <int> UpdateSmtpSettings(NewSMTPRequest source)
        {
            ValidateOptions(source);

            var targetRecord = GetSmtpSettingsByCompanyId(source.Company);

            if (targetRecord != null)
            {
                SMTPSettingsConverter.UpateModel(ref targetRecord, source);
                return(this._thermoDataContext.SaveChangesAsync());
            }

            return(Task.FromResult(-1));
        }
コード例 #4
0
        public virtual Task <int> SaveSmtpSettings(NewSMTPRequest source)
        {
            ValidateOptions(source);

            var targetRecord = GetSmtpSettingsByCompanyId(source.Company);

            if (targetRecord == null)
            {
                this._thermoDataContext.SMTPSettings.Add(source.ToModel());
                return(this._thermoDataContext.SaveChangesAsync());
            }

            return(Task.FromResult(-1));
        }
コード例 #5
0
        public async Task <IActionResult> Update([FromBody] NewSMTPRequest model)
        {
            try
            {
                var result = await _smtpDataService.UpdateSmtpSettings(model);

                if (result > 0)
                {
                    return(Ok(result));
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #6
0
 private void ValidateOptions(NewSMTPRequest source)
 {
     if (source == null)
     {
         throw new ArgumentNullException();
     }
     if (source.Company == 0)
     {
         throw new ArgumentException("Company is required");
     }
     if (source.Port == 0)
     {
         throw new ArgumentException("Port  is required");
     }
     if (string.IsNullOrWhiteSpace(source.HostName))
     {
         throw new ArgumentException("Hostname is required");
     }
 }