public async Task <IActionResult> Put([FromBody] UpdateBlog command) { command.AggregateRootId = BlogId; await _mediator.SendAndPublishAsync <UpdateBlog, Domain.Blogs.Blog>(command); return(new NoContentResult()); }
public void Setup() { _blog = BlogFactories.Blog(); _command = BlogFactories.UpdateBlogCommand(); _validatorMock = new Mock <IValidator <UpdateBlog> >(); _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult()); _blog.Update(_command, _validatorMock.Object); _event = _blog.Events.OfType <BlogUpdated>().Single(); }
public static BlogUpdated ToEvent(this UpdateBlog command) { return(new BlogUpdated { AggregateRootId = command.AggregateRootId, Title = command.Title, Theme = command.Theme }); }
public IActionResult UpdateBlog(UpdateBlog updateblog) { if (!ModelState.IsValid) { return(BadRequest("Enter the correct values")); } var(result, succeeded) = _commonServices.UpdateBlog(updateblog); if (succeeded) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult Update([Bind(Include = "Id,Title,Category,Text")] UpdateText BlogText)//文章更新提交 { if (ModelState.IsValid) { try { var IsUpdate = new UpdateBlog(BlogText); if (IsUpdate.IsSuccess == true) //TODO:更新成功处理 { return(Redirect("/manage/textlist")); } } catch (Exception) { throw; } } return(Redirect("/manage/textlist"));//TODO:更新失败处理 }
public (JsonResult result, bool Succeeded) UpdateBlog(UpdateBlog updateBlog) { try { BlogEntity blog = _context.BlogEntitys.FirstOrDefault(p => p.CategoryID == updateBlog.CategoryID); _context.Entry(blog).CurrentValues.SetValues(updateBlog); if (_context.SaveChanges() == 1) { return(new JsonResult("Blog updated successfully."), true); } else { return(new JsonResult("Enter the correct values."), false); } } catch (Exception ex) { return(new JsonResult("Some server error occured. Please try again!!"), false); } }
public async Task Setup() { _blog = BlogFactories.Blog(); _command = BlogFactories.UpdateBlogCommand(); _validatorMock = new Mock <IValidator <UpdateBlog> >(); _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult()); _blogRepositoryMock = new Mock <IBlogRepository>(); _blogRepositoryMock .Setup(x => x.GetByIdAsync(_command.AggregateRootId)) .ReturnsAsync(_blog); _blogRepositoryMock .Setup(x => x.UpdateAsync(It.IsAny <Domain.Blogs.Blog>())) .Callback <Domain.Blogs.Blog>(b => _updatedBlog = b) .Returns(Task.CompletedTask); _commandHandler = new UpdateBlogHandler(_blogRepositoryMock.Object, _validatorMock.Object); _result = await _commandHandler.HandleAsync(_command); _event = _updatedBlog.Events.OfType <BlogUpdated>().Single(); }
public void Update(UpdateBlog command, IValidator <UpdateBlog> validator) { validator.Validate(command); AddEvent(command.ToEvent()); }
public virtual async Task<ActionResult> EditBlog(UpdateBlog command) { return View(); }