private void Validate(SavePostCommand command, IPersistenceUnitOfWork uow) { // check duplicate name var postId = command.PostId; string newTitle = command.Title; if (uow.Context.Query <Entities.Posts.Post>().Any(p => p.Title == newTitle && p.Id != postId)) { throw new ValidationException($"Another post with '{newTitle}' title already exist"); } string newName = command.Name; if (uow.Context.Query <Entities.Posts.Post>().Any(p => p.Name == newName && p.Id != postId)) { throw new ValidationException($"Another post with '{newName}' url already exist"); } }
public async Task <IActionResult> Post(PostDTO item) { if (!ModelState.IsValid) { return(BadRequest(new ApiBadRequestResponse(ModelState))); } var command = new SavePostCommand(item); var handler = _factory.Build(command); var response = await handler.Execute(); if (response.Success) { item.PostId = response.ID; return(Ok(item)); } else { return(BadRequest(new ApiResponse(500))); } }
public ICommandHandler <SavePostCommand, CommandResponse> Build(SavePostCommand command) { return(new SavePostCommandHandler(_serviceProvider.GetService <IPostsRepository>(), command)); }
public NewTravelViewModel() { InsertPostCommand = new SavePostCommand(this); Post = new Post(); PostVenue = new Venue(); }