public async Task <Response <bool> > Handle(AddBookCommand request, CancellationToken cancellationToken)
        {
            var uploadedBookPhotosData = await fileManager.AddMultipleFileAsync(request.BookPhotos, FileTypeEnum.BookPhoto);

            var uploadedBookFileData = await fileManager.AddFileAsync(request.BookFile, FileTypeEnum.BookFile);

            var book = new Book
            {
                publishDate = request.PublishedDate,
                BookName    = request.BookName,

                AuthorId    = request.Userid,
                Price       = request.Price,
                Category    = (BookCategoryEnum)request.Category,
                Description = request.Description,
                File        = new File {
                    Url  = uploadedBookFileData.Url,
                    Path = uploadedBookFileData.Path
                },
                Imgs = uploadedBookPhotosData.Select(u => new Img {
                    Url  = u.Url,
                    Path = u.Path
                }).ToList()
            };
            await bookRepo.AddAsync(book);

            return(Response.Ok());
        }
Example #2
0
        public async Task <Response <bool> > Handle(RegisterUserCommand request, CancellationToken cancellationToken)
        {
            var uploadedFileData = await fileManager.AddFileAsync(request.Photo, FileTypeEnum.UserPhoto);

            var user = new User
            {
                FirstName = request.Username,
                LastName  = request.Lastname,
                UserName  = request.Username,
                Email     = request.Email,
                LastTimeSendConfirmLink = DateTime.Now,
                Img = new Img
                {
                    Url  = uploadedFileData.Url,
                    Path = uploadedFileData.Path
                }
            };


            await UserRepo.AddAsync(user, request.Password);

            //now , confirm email
            await emailSender.EmailConfirmationAsync(user);

            return(Response.Ok());
        }
Example #3
0
        public async Task <Response <bool> > Handle(UpdateUserPhotoCommand request, CancellationToken cancellationToken)
        {
            UploadedFileData uploadedData = await fileManager.AddFileAsync(request.Photo, FileTypeEnum.UserPhoto);

            Img userPhoto = await photoRepo.GetImgByUserIdAsync(request.Userid);

            // remove from hard
            fileManager.DeleteFile(userPhoto.Path);
            // remove from db
            await photoRepo.Remove(userPhoto);

            Img newImg = new Img {
                UserId = request.Userid,
                Url    = uploadedData.Url,
                Path   = uploadedData.Path
            };
            await photoRepo.AddAsync(newImg);

            return(Response.Ok());
        }
Example #4
0
        /// <summary>
        /// 素材上传OSS
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> UploadOSS(List <IFormFile> files, String tagId)
        {
            ReturnResult result = new ReturnResult();
            long         id     = long.Parse(tagId);

            foreach (var file in files)
            {
                ReturnResult check = OssOptionUtil.CheckFile(file);
                if (check.IsSuccess == false)//判断素材是否符合上传条件
                {
                    return(Json(check));
                }
                else
                {
                    //获取OSSkey
                    Dictionary <String, String> map = OssOptionUtil.GetOSSKey(file, OssOptionUtil.localhost_image, hostingEnvironment.WebRootPath, check.Message);
                    int count = await manager.GetFileCountByOssKey(map["fileKey"]);

                    if (count > 0)
                    {
                        await manager.UpdateTime(map["fileKey"]);//更新上传时间

                        result.Message = "上传成功";
                        return(Json(result));
                    }
                    else
                    {
                        FileParameter fileParameter = OssOptionUtil.OssUpload(map["filePath"], file, check.Message, id, map["fileKey"]);
                        await manager.AddFileAsync(fileParameter);

                        result.Message = "上传成功";
                        return(Json(result));
                    }
                }
            }
            result.IsSuccess = false;
            return(Json(result));
        }