public Video Create(CreateVideoCommand command) { var video = new Video(command.Url, command.TvAdditional, command.IdTypeVideo, command.IdTimeVideo, command.IdCompany, command.IdCategoryVideo, command.IdPlan, command.DateEnd, command.DateStart, command.ListVideoEquipment); //Marca todos itens da lista ListVideoEquipment com status Ativo foreach (var videoEquipment in command.ListVideoEquipment) { videoEquipment.Status = EStatusVideoEquipment.Ativo; videoEquipment.DateRegister = DateTime.Now; } video.Create(); _repository.Create(video); Commit(); foreach (var videoEquipment in command.ListVideoEquipment) { var item = _repositoryVideoEquipment.GetById(videoEquipment.IdVideoEquipment); decimal valueByTv = _repositoryBalance.GetValueByVideo(item.IdVideo); var history = new HistoryEquipment(item.IdVideo, item.IdEquipment, item.ControlLoan.IdCompany, item.Video.Plan.Description, EAction.Inclusão, valueByTv); history.Create(); _repositoryHistoryEquipment.Create(history); } if (Commit()) { return(video); } return(null); }
public void Should_Be_Valid_Command() { var _validCommand = new CreateVideoCommand(Guid.NewGuid(), "Video 1", VideoMock.GetFakeValidVideo(), "c:"); _validCommand.Validate(); Assert.True(!_validCommand.IsInvalid); }
public void Should_Be_Invalid_Command() { var _invalidCommand = new CreateVideoCommand(new Guid(), "", VideoMock.GetFakeInvalidVideo(), ""); _invalidCommand.Validate(); Assert.True(_invalidCommand.IsInvalid); }
public async Task Retornar_erro_quando_servidor_nao_existe() { var command = new CreateVideoCommand(Guid.NewGuid(), "video dia 01", "abc"); var result = await _handler.Handle(command, CancellationToken.None); result.IsFail.Should().BeTrue(); }
public CreateVideoHandlerTest() { _fakeServerRepository = new FakeServerRepository(_dataContextMock); _fakeVideoRepository = new FakeVideoRepository(_dataContextMock); _invalidCommand = new CreateVideoCommand(new Guid(), "", VideoMock.GetFakeInvalidVideo(), ""); var serverID = _dataContextMock.Servers.FirstOrDefault(); _validCommand = new CreateVideoCommand(serverID.Id, "Video 01", VideoMock.GetFakeValidVideo(), "c:"); }
public async Task Retornar_sucesso_ao_criar_video() { _serverRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>(), false)).ReturnsAsync(new Server("teste", "127.0.0.1", 1234)); var command = new CreateVideoCommand(Guid.NewGuid(), "video dia 01", "abc"); var result = await _handler.Handle(command, CancellationToken.None); _videoRepositoryMock.Verify(x => x.SaveContent("abc"), Times.Once()); _serverRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once()); }
public void Add(VideoModel videoModel) { Video video = new Video(videoModel.Description, videoModel.AuthorAccount, videoModel.Url, videoModel.Lable, videoModel.Size, 0 ); CreateVideoCommand command = new CreateVideoCommand(video); _eventBus.Publish(command); }
public Task <HttpResponseMessage> Post([FromBody] dynamic body) { var command = new CreateVideoCommand( url: (string)body.url, tvAdditional: (int)body.tvAdditional, idTimeVideo: (int)body.idTimeVideo, idTypeVideo: (int)body.idTypeVideo, idCompany: (int)body.idCompany, idCategoryVideo: (int)body.idCategoryVideo, idPlan: (int)body.idPlan, dateEnd: (DateTime)body.dateEnd, dateStart: (DateTime)body.dateStart, listVideoEquipment: body.listVideoEquipment.ToObject <List <VideoEquipment> >() ); var video = _service.Create(command); return(CreateResponse(HttpStatusCode.Created, video)); }
public async Task <IActionResult> Add(Guid serverId, [FromBody] CreateVideoCommand command) { command.ServerId = serverId; try { var result = await _mediator.Send(command); if (result.IsSuccess) { var viewModel = new VideoViewModel(result.SuccessData.Id, result.SuccessData.Description); return(Created($"/servers/{serverId}/videos/{viewModel.Id}", viewModel)); } return(NotFound(result.FailData)); } catch (Exception) { return(BadRequest("Não foi possível adicionar o vídeo, tente novamente mais tarde.")); } }
public async Task <ActionResult <int> > Create(CreateVideoCommand command) { command.UserId = _currentUserService.UserId; return(await Mediator.Send(command)); }
public IActionResult Create([FromServices] VideoHandler handler, [FromRoute] Guid serverId, [FromBody] CreateVideoCommand command) { command.ServerId = serverId; command.FileSystemPath = AppFileSystem.VideosPath; var response = (DefaultCommandResult)handler.Handle(command); return(this.DefaultCommandResultToActionResult(response)); }