コード例 #1
0
        public async Task <WallpaperModel> CreateWallpaperDraft(IFormCollection fc)
        {
            if (fc != null && fc.Files.Count > 0 && fc.Files[0].Length > 0)
            {
                var formFile = fc.Files[0];
                var info     = new WallpaperProjectInfo()
                {
                    File = formFile.FileName
                };
                var targetDir = await WallpaperApi.CreateWallpaperDraft(AppManager.UserSetting.Wallpaper.WallpaperSaveDir, info);

                var distFile = Path.Combine(targetDir, formFile.FileName);
                using var stream = System.IO.File.Create(distFile);
                await formFile.CopyToAsync(stream);

                var r = WallpaperApi.CreateWallpaperModel(distFile);
                if (string.IsNullOrEmpty(r.Info.Title))
                {
                    int lastIndex = r.Info.File.LastIndexOf(".");
                    r.Info.Title = r.Info.File.Remove(lastIndex);
                }

                return(r);
            }
            return(null);
        }