public async Task <ResultStatusType> Handle(AddBookInfo request, CancellationToken cancellationToken, RequestHandlerDelegate <ResultStatusType> next) { var bookValid = new AddBookInfoValidation(); var check = bookValid.Validate(request); if (check.IsValid) { return(await next()); } else { throw new Exception("Not Valid"); } }
public async Task <IActionResult> AddBook(AddBookViewModel book, IFormFile imagePath) { var imageName = "BookDefault.jpg"; if (imagePath == null) { ModelState.AddModelError("ImageName", "تصویر اجباری می باشد"); return(View(book)); } else { imageName = Generator.GenerateGuid() + Path.GetExtension(imagePath.FileName); using (var stream = new FileStream(Directory.GetCurrentDirectory() + "/wwwroot/Images/" + imageName, FileMode.Create)) { imagePath.CopyTo(stream); } } var query = new AddBookInfo() { ShabekNo = book.ShabekNo, Subject = book.Subject, BookName = book.BookName, Content = book.Content, ImageName = imageName }; var res = await _mediator.Send(query); switch (res) { case ResultStatusType.Success: return(RedirectToAction("Index")); case ResultStatusType.Error: return(View(book)); default: return(View(book)); } }