Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void Execute(UpdateBlogCommand command)
        {
            Contract.Requires(command != null);

            var item = new Blog(command.Id, command.Name, command.Url);

            this._updateRepository.Update(item);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> EditAsync(Guid Id, UpdateBlogCommand command)
        {
            if (Id != command.Id)
            {
                return(BadRequest());
            }
            await Mediator.Send(command);

            return(NoContent());
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
 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.")));
     }
 }
Exemplo n.º 8
0
 protected override void Establish_context()
 {
     base.Establish_context();
     this._command = new UpdateBlogCommand(Guid.NewGuid(), "Blog name", "www.url.com");
 }
Exemplo n.º 9
0
 public async Task <ActionResult <int> > Update(UpdateBlogCommand command)
 {
     return(await Mediator.Send(command));
 }
Exemplo n.º 10
0
 public void Validate(UpdateBlogCommand command)
 {
     //this.ValidateCreateOrUpdate(command);
 }
Exemplo n.º 11
0
        public async Task <ValidationResult> Update(UpdateBlogViewModel updateBlogViewModel)
        {
            UpdateBlogCommand updateBlogCommand = _mapper.Map <UpdateBlogCommand>(updateBlogViewModel);

            return(await _mediator.Send(updateBlogCommand));
        }