示例#1
0
        public async Task <IActionResult> CreateBackground(CreateBackgroundModel model)
        {
            var board = _boards.GetEntity(model.BoardId);

            if (board == null)
            {
                return(RedirectToAction("Boards"));
            }
            var imagePath = $"/{ImageStorageFolder}/{model.File.FileName}";

            await SaveImageAsync(model, imagePath);

            var thumbnailName = $"min.{model.File.FileName}";
            var thumbnailPath = $"/{ThumbnailStorageFolder}/{thumbnailName}";

            SaveThumbnail(model, thumbnailPath);
            var image = new Image
            {
                Name      = model.File.FileName,
                ImageType = model.Type,
                Path      = imagePath,
                Boards    = new List <Board> {
                    board
                }
            };
            var thumbnail = new Thumbnail
            {
                Name  = thumbnailName,
                Path  = thumbnailPath,
                User  = board.User,
                Image = image
            };

            image.Thumbnail = thumbnail;
            _images.AddEntity(image);
            _images.Save();
            return(RedirectToAction("Board", new { id = model.BoardId }));
        }