Пример #1
0
        public async Task <OperationResult <string> > Handle(CreatePostMagazineCommands request, CancellationToken cancellationToken)
        {
            ///Upload Poster
            var uploadFile = await UploadUtiltie.UploadInCustomePath(request.Photo, ".png", request.Title, UploadFolderPath.PathPosterUploadFolder(), UploadFolderPath.PathPosterUpload());

            if (uploadFile.Success)
            {
                /// Add New Post
                PostMagazine postMagazine = new PostMagazine(request.Title, request.Description, uploadFile.Result, request.PostContent, request.DownloadLink, request.SubTitleLink, request.CategoryId, request.WriterId);
                var          add          = await unitOfWork.PostMagazineRepository.AddPostManagazinAsync(postMagazine, cancellationToken);

                if (add.Success)
                {
                    try
                    {
                        await unitOfWork.CommitSaveChangeAsync();

                        return(OperationResult <string> .BuildSuccessResult("Add Success"));
                    }
                    catch (Exception ex)
                    {
                        return(OperationResult <string> .BuildSuccessResult(ex.Message));
                    }
                }
            }
            return(OperationResult <string> .BuildSuccessResult(uploadFile.ErrorMessage));
        }
Пример #2
0
        public async Task <OperationResult <string> > Handle(CreatePostMagazineCommands request, CancellationToken cancellationToken, RequestHandlerDelegate <OperationResult <string> > next)
        {
            var findUserName = await unitOfWork.CategoryRepository.GetCategoryByIdAsync(request.CategoryId, cancellationToken);

            if (findUserName.Result != null)
            {
                return(OperationResult <string> .BuildFailure("Category NotFound"));
            }
            return(await next());
        }