public bool Handle(NewChannelRequest request, IOutputPort <NewChannelResponse> outputPort) { if (_userRepository.FindById(request.UserId) == null) { outputPort.Handle(new NewChannelResponse(new[] { new Error(404, "user not found") })); return(false); } if (_channelRepository.FindByUserId(request.UserId) != null) { outputPort.Handle(new NewChannelResponse(new[] { new Error(422, "user already have channel") })); return(false); } if (_channelRepository.FindByName(request.Name) != null) { outputPort.Handle(new NewChannelResponse(new[] { new Error(422, "channel name is busy") })); return(false); } var channelInfo = new ChannelDto() { UserId = request.UserId, RegistrationDate = request.RegistrationDate, Description = request.Description, Name = request.Name, }; ChannelDto createdChannel = _channelRepository.Create(channelInfo); outputPort.Handle(new NewChannelResponse(createdChannel)); return(true); }
public ActionResult CreateChannel([FromBody] Models.Requests.NewChannelRequest request) { try { _newChannelValidator.ValidateAndThrow(request); } catch (ValidationException e) { return(BadRequest(e.Errors)); } var newChannelRequest = new NewChannelRequest( int.Parse(User.Id()), DateTime.Now, request.Description, request.Name ); _newChannelUseCase.Handle(newChannelRequest, _newChannelPresenter); return(_newChannelPresenter.ContentResult); }
public IActionResult CreateChannel([FromForm] NewChannelRequest request) { service.CreateChannel(request); return(RedirectToAction(nameof(GetChannels))); }
public void CreateChannel(NewChannelRequest request) { var url = "API/CHANNEL"; PostDataToApi <object, NewChannelRequest>(request, url); }