public void Handle(UpdateBlogCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } var blog = new Models.Blog(message.Id, message.Name, message.Title, message.Slug, message.Description, message.CreatedUtc, message.ModifiedUtc, message.PublishedUtc, message.CreatedByUserId, message.CommonStatusId); var existingBlog = _blogRepository.GetByName(blog.Name); if (existingBlog != null) { if (!existingBlog.Equals(blog)) { Bus.RaiseEvent(new DomainNotification(message.MessageType, "The blog name has already been taken.")); return; } } _blogRepository.Update(blog); if (Commit()) { Bus.RaiseEvent(new BlogUpdatedEvent(blog.Id, blog.Name, blog.Title, blog.Slug, blog.Description, blog.CreatedUtc, blog.ModifiedUtc, blog.PublishedUtc, blog.CreatedByUserId, blog.CommonStatusId)); } }
public void then_if_the_command_is_null_exception_is_thrown() { this._command = null; this.Execute(); var expected = "Precondition failed: command != null"; this._errorMessage.ShouldEqual(expected); }
public void Execute(UpdateBlogCommand command) { Contract.Requires(command != null); var item = new Blog(command.Id, command.Name, command.Url); this._updateRepository.Update(item); }
public async Task <ActionResult> EditAsync(Guid Id, UpdateBlogCommand command) { if (Id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public void Update(UpdateBlogCommand updatedBlogCommand) { var repo = new BlogRepository(); //var updatedBlog = new Blog //{ // Title = updatedBlogCommand.Title, // Article = updatedBlogCommand.Article, // ImageUrl = updatedBlogCommand.ImageUrl, // }; repo.UpdateBlog(updatedBlogCommand); }
public bool UpdateBlog(UpdateBlogCommand updatedBlog) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); var sql = @"UPDATE [dbo].[Blog] SET [Title] = @Title, [Article] = @Article, [ImageUrl] = @ImageUrl WHERE [Id] = @BlogId" ; return(connection.Execute(sql, updatedBlog) == 1); } }
public async Task <ActionResult> Put(int id, [FromBody] UpdateBlogCommand command) { if (id == command.Id) { var result = await Mediator.Send(command);; if (result > 0) { return(Ok(new ApiResponse(result, string.Format("Blog with Id {0} updated.", result)))); } else { return(BadRequest(new ApiResponse(new string[] { "Unable to update blog." }, "Unable to update blog."))); } } else { return(BadRequest(new ApiResponse(new string[] { "Id is not valid." }, "Id is not valid."))); } }
protected override void Establish_context() { base.Establish_context(); this._command = new UpdateBlogCommand(Guid.NewGuid(), "Blog name", "www.url.com"); }
public async Task <ActionResult <int> > Update(UpdateBlogCommand command) { return(await Mediator.Send(command)); }
public void Validate(UpdateBlogCommand command) { //this.ValidateCreateOrUpdate(command); }
public async Task <ValidationResult> Update(UpdateBlogViewModel updateBlogViewModel) { UpdateBlogCommand updateBlogCommand = _mapper.Map <UpdateBlogCommand>(updateBlogViewModel); return(await _mediator.Send(updateBlogCommand)); }