public async Task <ActionResult> Put(EmployeeRest employee) { var command = new UpdateEmployeeCommand(employee); await _mediator.Send(command); return(NoContent()); }
public async Task ShouldUpdateEmployee() { var userId = await RunAsDefaultUserAsync(); var employeeId = await SendAsync(new CreateEmployeeCommand { FirstName = "BeforeUpdateFirstName", LastName = "BeforeUpdateLastName", Email = "*****@*****.**", Pesel = "12345612" }); var command = new UpdateEmployeeCommand { Id = employeeId, FirstName = "AfterUpdateFirstName", LastName = "AfterUpdateLastName", Email = "*****@*****.**", Pesel = "2222222" }; await SendAsync(command); var empl = await FindAsync <Employee>(employeeId); empl.Should().NotBeNull(); empl.FirstName.Should().Be(command.FirstName); empl.LastName.Should().Be(command.LastName); empl.Email.Should().Be(command.Email); empl.Pesel.Should().Be(command.Pesel); empl.LastModifiedBy.Should().NotBeNull(); empl.LastModifiedBy.Should().Be(userId); empl.LastModified.Should().NotBeNull(); empl.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task <ActionResult> Put([FromRoute] int employeeId, [FromBody] UpdateEmployeeCommand updateEmployeeCommand) { await this._mediator.Send(updateEmployeeCommand); return(Ok()); }
public async System.Threading.Tasks.Task ShouldUpdateEmployee() { var userId = await RunAsDefaultUserAsync(); var employeeId = await SendAsync(new CreateEmployeeCommand { Name = "John Smith" }); var command = new UpdateEmployeeCommand { Id = employeeId, Name = "John Becker" }; await SendAsync(command); var list = await FindAsync <Employee>(employeeId); list.Name.Should().Be(command.Name); list.LastModifiedBy.Should().NotBeNull(); list.LastModifiedBy.Should().Be(userId); list.LastModified.Should().NotBeNull(); list.LastModified.Should().BeCloseTo(DateTime.Now, 1000); }
public async Task <IActionResult> Update(int id, UpdateEmployeeCommand command) { if (id != command.Id) { return(BadRequest()); } return(Ok(await _mediator.Send(command))); }
public IActionResult UpdateEmployee([FromBody] EmployeeDto employeeDto) { EnsureArg.IsNotNull(employeeDto); var command = new UpdateEmployeeCommand(employeeDto); CommandDispatcher.Execute(command); return(NoContent()); }
public void UpdateEmployee(int Id, Employee employee) { var updateEmployee = new UpdateEmployeeCommand(employee.Id, employee.FirstName, employee.LastName, employee.Age, employee.Salary); _bus.SendCommand(updateEmployee); }
public async Task <IActionResult> Update(UpdateEmployeeCommand updateEmployeeCommand) { var result = await _mediator.Send(updateEmployeeCommand); if (!result.Success) { return(BadRequest(result.Message)); } return(Ok(result.Message)); }
public async Task <IActionResult> EditEmployee([FromBody, NotNull, CustomizeValidator(RuleSet = "PreValidationEmployeeUpdate")] UpdateEmployeeCommand model) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _mediator.Send(model); return(result.IsFailure ? (IActionResult)BadRequest(result.Error) : Ok(result.Value)); //FP is here }
public async void EmployeeShouldThrowNotFoundException() { var updatedEmployee = new UpdateEmployeeCommand { Id = GConst.InvalidId, FirstName = GConst.ValidName }; var status = await Record.ExceptionAsync(async() => await sut.Handle(updatedEmployee, CancellationToken.None)); Assert.NotNull(status); Assert.Equal(string.Format(GConst.NotFoundExceptionMessage, GConst.Employee, GConst.InvalidId), status.Message); }
public async Task <IActionResult> Update(UpdateEmployeeCommand updateEmployeeCommand) { var result = await Mediator.Send(updateEmployeeCommand); if (result.Success == false) { return(result.ApiResult); } return(NoContent()); }
public async Task <ActionResult <Result> > UpdateEmployee([FromBody] UpdateEmployeeCommand command) { var result = await Mediator.Send(command); if (!result.Succeeded) { return(BadRequest(result)); } return(Ok(result)); }
public void ShouldRequireValidEmployeeId() { var command = new UpdateEmployeeCommand { Id = 99, Name = "John Smith" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <ActionResult> Update(int id, UpdateEmployeeCommand command) { if (id != command.Id) { return(BadRequest()); } await Mediator.Send(command); return(NoContent()); }
public async Task <Response> Handle(UpdateEmployeeCommand request, CancellationToken cancellationToken) { var employee = repository.GetById(request.Id); employee.Name = request.Name; employee.Description = request.Description; repository.Update(employee); await repository.SaveChanges(); return(await Task.FromResult(new Response(employee))); }
public IActionResult UpdateEmployee(string id, [FromBody] UpdateEmployeeCommand command) { command.Id = id; var result = _mediator.Send(command); if (result.IsFaulted) { return(BadRequest(result.Exception.InnerException.Message)); } return(NoContent()); }
public void ShouldRequireValidEmployeeId() { var command = new UpdateEmployeeCommand { Id = 99999, FirstName = "ToUpdateFirstName", LastName = "ToUpdateLastName", Email = "*****@*****.**", Pesel = "12345612" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async void EmployeeShouldUpdateCorrect() { var updatedEmployee = new UpdateEmployeeCommand { Id = employeeId, FirstName = GConst.ValidName, LocationId = locationId }; var status = Task <Unit> .FromResult(await sut.Handle(updatedEmployee, CancellationToken.None)); var resultId = context.Employees.SingleOrDefault(x => x.FirstName == GConst.ValidName).Id; Assert.Equal(employeeId, resultId); Assert.Equal(GConst.SuccessStatus, status.Status.ToString()); Assert.Equal(GConst.ValidCount, context.Employees.Count()); }
public async Task <IActionResult> UpdateEmployee(int employeeId, [FromBody] Employee employee) { _logger.Debug("Update new employee"); employee.EmployeeId = employeeId; var command = new UpdateEmployeeCommand { Employee = employee }; await _mediator.Send(command); return(Ok()); }
public IResult Handler(UpdateEmployeeCommand command) { var employee = new Employee(command.Name, command.Brithdate, command.Phone, new Address(command.City, command.Neighborhood, command.ZipCode, command.Country, command.Street, command.State), new Email(command.Address)); AddNotifications(employee); if (employee.Invalid) { return(new CommandResult(false, "Dados inválidos", null, Notifications)); } var employeeCreated = _employeeRepository.Save(employee); return(new CommandResult(true, "Funcionário atualizado com sucesso", new EmployeeUpdatedViewModel(employeeCreated.Id, employeeCreated.Name), Notifications)); }
public async Task <Result <Employee> > Handle(UpdateEmployeeCommand request, CancellationToken cancellationToken) { var result = _validator.Validate(request, ruleSet: "PreValidationEmployeeUpdate"); if (result.Errors.Count > 0) { return(Result.Failure <Employee>(result.Errors.First().ErrorMessage)); } var employeeDb = _mapper.Map <EmployeeDb>(request); _context.Entry(employeeDb).State = EntityState.Modified; await _context.SaveChangesAsync(cancellationToken); return(Result.Ok <Employee>(_mapper.Map <Employee>(employeeDb))); }
public async Task <ApiResponse <Guid> > UpdateEmployee(EmployeeDetailViewModel employeeDetailViewModel) { try { UpdateEmployeeCommand updateEmployeeCommand = _mapper.Map <UpdateEmployeeCommand>(employeeDetailViewModel); await _client.UpdateEmployeeAsync(updateEmployeeCommand); return(new ApiResponse <Guid>() { Success = true }); } catch (ApiException ex) { return(ConvertApiExceptions <Guid>(ex)); } }
public async Task <IActionResult> Edit(EmployeeDetailVM employeeDetailVM) { var updateEmployeeCommand = new UpdateEmployeeCommand() { EmployeeId = employeeDetailVM.EmployeeId, FirstName = employeeDetailVM.FirstName, LastName = employeeDetailVM.LastName, CNIC = employeeDetailVM.CNIC, Email = employeeDetailVM.Email, Age = employeeDetailVM.Age, Address = employeeDetailVM.Address }; //var updateTenantCommand = _mapper.Map<UpdateTenantCommand>(tenantDetailVM); var employee = await Mediator.Send(updateEmployeeCommand); return(RedirectToAction("List")); }
public async Task <CommandHandlingResult> Handle(UpdateEmployeeCommand command, IEventPublisher publisher) { var employee = Mapper.Map <Employee>(command); try { await _employeeService.UpdateAsync(employee); } catch (Exception e) { if (e is EmployeeNotFoundException notFoundEx) { _log.WarningWithDetails(notFoundEx.Message, new { notFoundEx.EmployeeId }); } if (e is EmployeeExistException existsEx) { _log.WarningWithDetails(existsEx.Message, new { command.Email }); } publisher.PublishEvent(new EmployeeUpdateFailedEvent { Email = command.Email, Error = e.Message }); _chaosKitty.Meow("Issue with RabbitMq publishing EmployeeUpdateFailedEvent"); return(CommandHandlingResult.Ok()); } publisher.PublishEvent(new EmployeeUpdatedEvent { Id = employee.Id, Email = employee.Email, MerchantId = employee.MerchantId, Password = command.Password }); _chaosKitty.Meow("Issue with RabbitMq publishing EmployeeUpdatedEvent"); return(CommandHandlingResult.Ok()); }
// constructor public EmployeeViewModel() { dbConnectionString = Properties.Settings.Default.DBConnectionString; // initialize button enable logic bCanDelete = false; bCanAdd = true; bCanEdit = false; bCanUpdate = false; bCanCancel = false; // initialize control commands AddEmployee = new AddEmployeeCommand(this); EditEmployee = new EditEmployeeCommand(this); UpdateEmployee = new UpdateEmployeeCommand(this); DeleteEmployee = new DeleteEmployeeCommand(this); CancelChanges = new CancelChangesCommand(this); // retrieve employee list and populate DataGrid control FillDataGrid(); SelectedItem = -1; OnPropertyChanged("SelectedItem"); }
public async System.Threading.Tasks.Task ShouldRequireUniqueName() { var employeeId = await SendAsync(new CreateEmployeeCommand { Name = "John Smith" }); await SendAsync(new CreateEmployeeCommand { Name = "Jane" }); var command = new UpdateEmployeeCommand { Id = employeeId, Name = "Jane" }; FluentActions.Invoking(() => SendAsync(command)) .Should().Throw <ValidationException>().Where(ex => ex.Errors.ContainsKey("Name")) .And.Errors["Name"].Should().Contain("The specified name already exists."); }
public async Task <IActionResult> UpdateEmployee([FromBody] UpdateEmployeeCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task <ActionResult> Put([FromBody] UpdateEmployeeCommand command) { await _mediator.Publish(command); return(Ok()); }
public Task <Unit> Handle(UpdateEmployeeCommand request, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public async Task <UpdateEmployeeCommandResponse> UpdateEmployee([FromBody] UpdateEmployeeCommand employee) { return(await _mediator.Send(employee)); }