Beispiel #1
0
        public IActionResult EditPlatformSetting()
        {
            var settings = _settingFinder.Get <PlatformSetting>();
            PlatformSettingModel model = new PlatformSettingModel
            {
                AppName                  = settings.AppName,
                AppVersion               = settings.VersionNumber,
                DataLogEnabled           = settings.DataLogEnabled,
                LogEnabled               = settings.LogEnabled,
                LogLevel                 = (int)settings.LogLevel,
                ShowMenuInUserPrivileges = settings.ShowMenuInUserPrivileges,
                MaxFetchRecords          = settings.MaxFetchRecords
            };

            return(View(model));
        }
Beispiel #2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static async Task <SaveFileResult> SaveAs(this IFormFile file, string path, ISettingFinder settingFinder, IWebHelper webHelper)
        {
            SaveFileResult result = new SaveFileResult();

            if (file == null)
            {
                result.IsSuccess = false;
                result.Status    = -1;
                result.Error     = "file is null";
            }
            else
            {
                string fileName = file.FileName;
                string fileExt  = Path.GetExtension(fileName);
                var    config   = settingFinder.Get <UploadSetting>();
                if (!config.FileExts.IsNotEmpty() && !config.FileExts.Split(';').Contains(fileExt, StringComparer.InvariantCultureIgnoreCase))
                {
                    result.IsSuccess = false;
                    result.Status    = -2;
                    result.Error     = "file extension is forbidden";
                }
                else
                {
                    long fileSize = file.Length;
                    if (fileSize > config.MaxSize * 1024)
                    {
                        result.IsSuccess = false;
                        result.Status    = -3;
                        result.Error     = $"file size is greater than {config.MaxSize}kb";
                    }
                }
                if (path.IsEmpty())
                {
                    string dirPath     = webHelper.MapPath("/upload/attachment/");
                    string name        = DateTime.Now.ToString(config.FormatName);//"yyMMddHHmmssfffffff"
                    string newFileName = name + fileExt;

                    path = dirPath + newFileName;
                }

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await file.CopyToAsync(stream).ConfigureAwait(false);
                }
                result.IsSuccess = true;
                result.FilePath  = path;
            }
            return(result);
        }
Beispiel #3
0
 public IActionResult SendEmails([FromBody] SendEmailsModel model)
 {
     if (ModelState.IsValid)
     {
         var emails = model.EmailAddresses.SplitSafe(",");
         if (emails.IsEmpty())
         {
             return(JError(T["noneemailsettings"]));
         }
         EmailSetting emailSettings = _settingFinder.Get <EmailSetting>();
         if (emailSettings.Host.IsEmpty())
         {
             return(JError(T["noneemailsettings"]));
         }
         var _emailMessageHandler = new EmailMessageHandler();
         foreach (var em in emails)
         {
             _emailMessageHandler.Send(new EmailNotifyBody()
             {
                 Subject = model.Subject
                 ,
                 Content = model.Content
                 ,
                 Host = emailSettings.Host
                 ,
                 Port = int.Parse(emailSettings.Port)
                 ,
                 UserName = emailSettings.UserName
                 ,
                 Password = emailSettings.Password
                 ,
                 From = emailSettings.From
                 ,
                 FromName = emailSettings.FromName
                 ,
                 To = em
             });
         }
         return(JOk(T["operation_success"]));
     }
     return(JError(T["operation_error"] + ": " + GetModelErrors()));
 }