public static EmployeeAggregateRoot Register(IWorkContext context, CreateEmployeeCommand command) { var user = new EmployeeAggregateRoot(command.AggregateId); user.Create(context, command); return(user); }
public async Task ShouldCreateCreateEmployee() { var userId = await RunAsDefaultUserAsync(); var command = new CreateEmployeeCommand { FirstName = "TestFirstName", LastName = "TestLastName", Email = "*****@*****.**", Pesel = "12345612" }; var employeeId = 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.CreatedBy.Should().Be(userId); empl.Created.Should().BeCloseTo(DateTime.Now, 10000); empl.LastModifiedBy.Should().BeNull(); empl.LastModified.Should().BeNull(); }
public async Task <ICommandResult> HandleAsync(CreateEmployeeCommand command) { if (command == null) { return(new GenericCommandResult(false, "Comando inválido", NotificationHelpers.BuildNotifications(new Notification("body", "O corpo da requisição não pode ser nulo verifique as propriedades enviadas")))); } command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Comando inválido", command.Notifications)); } if (_repository.CheckEmailAlreadyExists(command.Email)) { return(new GenericCommandResult(false, "Comando inválido", NotificationHelpers.BuildNotifications(new Notification("Email", "Email já registrado em nossa base")))); } var user = new Employee(command); user.Validate(); if (user.Invalid) { return(new GenericCommandResult(false, "Comando inválido", user.Notifications)); } await _repository.Insert(user); return(new GenericCommandResult(true, "Funcionario Cadastrado com sucesso", null)); }
public void ShouldRequireMinimumFields() { var command = new CreateEmployeeCommand(); FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task <IActionResult> Create(CreateEmployeeCommand command) { if (!ModelState.IsValid) { return(View()); } try { await Mediator.Send(command); } catch (ModelStateException ex) { if (ex.ModelStates.Count > 0) { foreach (var key in ex.ModelStates) { ModelState.AddModelError(key, ex.Message); } } else { ModelState.AddModelError(string.Empty, ex.Message); } return(View()); } return(Redirect(nameof(Index))); }
public async Task <ActionResult <int> > Post(EmployeeRest employee) { var command = new CreateEmployeeCommand(employee); var id = await _mediator.Send(command); return(Ok(id)); }
public async Task <ActionResult <int> > Post([FromBody] CreateEmployeeCommand createEmployeeCommand) { // var employeeId = await this._mediator.Send(createEmployeeCommand); var employeeId = await this._mediator.Send(createEmployeeCommand); return(Ok(employeeId)); }
public async Task <IActionResult> Create([FromBody] CreateEmployeeCommand command) { var employee = new Employee(command.FullName, command.Email, command.Salary); var createEmployee = await _repo.Create(employee); return(StatusCode(201)); }
public async Task <JsonResult> SaveEmployee(EmployeeVM data) { var _cmd = new CreateEmployeeCommand(data); var _result = await mediator.Send(_cmd); return(Json(_result)); }
private IFormVm BuildAddForm(CreateEmployeeCommand command) => BuildPageBase().Link(RelTypes.Self, "New Employee", AddUri()) .Link(RelTypes.Breadcrumb, "New Employee", AddUri()) .Property(nameof(CreateEmployeeCommand.FirstName), "First Name", command.FirstName) .Property(nameof(CreateEmployeeCommand.LastName), "Last Name", command.LastName) .Property(nameof(CreateEmployeeCommand.EmployeeNo), "Employee No", command.EmployeeNo) .Property(nameof(CreateEmployeeCommand.Email), "Email", command.Email) .Build() .ToFormVm();
public async Task <IActionResult> Add(EmployeeDTO serviceDTO) { var createServiceCommand = new CreateEmployeeCommand(); // serviceDTO.EmployeeId = 1; createServiceCommand.EmployeeDTO = serviceDTO; int result = await Mediator.Send(createServiceCommand); return(RedirectToAction("List")); }
public async Task <IActionResult> Create(CreateEmployeeCommand createEmployeeCommand) { var result = await _mediator.Send(createEmployeeCommand); if (!result.Success) { return(BadRequest(result.Message)); } return(Ok(result.Message)); }
public async Task <IActionResult> Create(CreateEmployeeCommand employee) { var result = (CreateEmployeeCommandResult)EmployeeHandler.Handle(employee).GetAwaiter().GetResult(); if (!result.Validation) { ViewBag.Validation = EmployeeHandler.Notifications.Select(x => x.Message); return(View(employee)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(CreateEmployeeCommand createEmployee) { var result = await Mediator.Send(createEmployee); if (result.Success == false) { return(result.ApiResult); } return(Created(Url.Link("GetEmployeeInfo", new { id = result.Data.Id }), result.Data)); }
public async Task <IActionResult> Index() { var command = new CreateEmployeeCommand() { Name = "Hans", }; await Mediator.Send(command); return(View()); }
public async Task <IActionResult> CreateEmployee([FromBody, NotNull, CustomizeValidator(RuleSet = "PreValidationEmployee")] CreateEmployeeCommand model) { if (!ModelState.IsValid) { _logger.LogError($"Invalid model for create a new employee was used."); return(BadRequest()); } var result = await _mediator.Send(model); return(result.IsFailure ? (IActionResult)BadRequest(result.Error) : Ok(result.Value)); //FP is here }
public async Task <Guid> CreateEmployee(string name) { var command = new CreateEmployeeCommand { Id = Guid.NewGuid(), Name = name }; await _createEmployeeCommandHandler.Handle(command); return(command.Id); }
public async Task <IActionResult> Add(CreateEmployeeCommand command) { if (ModelState.IsValid == false) { var vm = BuildAddForm(command); return(PartialView(vm)); } await _employeeService.HandleAsync(command); return(RedirectToAction(nameof(Index), new SearchEmployeeQuery(command.EmployeeNo))); }
public async Task <IActionResult> Create([Bind("EmployeeID,DepartmentID,Surname,Name,Patronymic,DateOfBirth")] Employee employee) { if (ModelState.IsValid) { var command = new CreateEmployeeCommand(employee); var handler = CommandHandlerFactory.Build(command); handler.Execute(_context); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentID"] = new SelectList(_context.Department, "DepartmentID", "DepartmentID", employee.DepartmentID); return(View(employee)); }
public async Task <Guid> CreateEmployeeAsync(CreateEmployeeCommand command) { var employee = new Employee( command.Name, command.DisplayName, command.BirthDate, command.Gender, command.MaritalStatus); _employeeRepository.Add(employee); await _unitOfWork.CommitAsync(); return(employee.Id); }
public async Task <Response> Handle(CreateEmployeeCommand request, CancellationToken cancellationToken) { var employee = new Employee { Name = request.Name, Description = request.Description }; await repository.Create(employee); await repository.SaveChanges(); return(await Task.FromResult(new Response(employee))); }
public async Task <ActionResult <Employee> > Post([FromBody] Employee employee) { var command = new CreateEmployeeCommand { EmpId = employee.EmpId, Name = employee.Name, Address = employee.Address, Phone = employee.Phone }; var result = await this.mediator.Send(command); return(Ok(result)); }
public override async Task <GuidRequired> CreateEmployee(CreateEmployeeRequest request, ServerCallContext context) { var command = new CreateEmployeeCommand { Name = request.Name, DisplayName = request.DisplayName, BirthDate = request.BirthDate.ToDateTime(), Gender = (Gender)request.Gender, MaritalStatus = (MaritalStatus)request.MaritalStatus, }; var result = await _organizationApp.CreateEmployeeAsync(command); return(result); }
public async Task <IActionResult> CreateBook([FromBody] Employee employee) { if (ModelState.IsValid) { var command = new CreateEmployeeCommand(employee); var result = await _mediator.Send(command); return(Ok(result)); } else { return(BadRequest(ModelState)); } }
protected void Create(IWorkContext context, CreateEmployeeCommand command) { this.ApplyEvent(new CreateEmployeeEvent() { AggregateId = this.AggregateId, UserName = command.UserName, NickName = command.NickName, Version = this.Version, CreateDate = context.WorkTime, Password = command.Password, Creator = context.GetWorkerName(), DepartmentId = command.DepartmentId, GroupSort = command.GroupSort }); }
public async System.Threading.Tasks.Task ShouldRequireUniqueName() { await SendAsync(new CreateEmployeeCommand { Name = "John Smith" }); var command = new CreateEmployeeCommand { Name = "John Smith" }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>(); }
public Employee(CreateEmployeeCommand command) { FullName = command.FullName; BirthDate = command.BirthDate; Email = command.Email; Gender = command.Gender; Id = Guid.NewGuid(); Skills = new List <EmployeeSkill>(); foreach (var item in command.Skills) { Skills.Add(new EmployeeSkill(Id, item)); } Enabled = true; CreationDate = DateTime.Now; }
public async Task <Result <Employee> > Handle(CreateEmployeeCommand request, CancellationToken cancellationToken) { var result = _validator.Validate(request, ruleSet: "CheckExistingEmployeeValidation"); if (result.Errors.Count > 0) { return(Result.Failure <Employee>(result.Errors.First().ErrorMessage)); } var employeeDb = _mapper.Map <EmployeeDb>(request); _context.Add(employeeDb); await _context.SaveChangesAsync(cancellationToken); return(Result.Ok <Employee>(_mapper.Map <Employee>(employeeDb))); }
public async Task <ApiResponse <int> > CreateEmployee(EmployeeDetailViewModel employeeDetailViewModel) { try { CreateEmployeeCommand createEmployeeCommand = _mapper.Map <CreateEmployeeCommand>(employeeDetailViewModel); var response = await _client.AddEmployeeAsync(createEmployeeCommand); return(new ApiResponse <int>() { Data = response.Employee.EmployeeId, Success = true }); } catch (ApiException ex) { return(ConvertApiExceptions <int>(ex)); } }
public Employee Create(CreateEmployeeCommand command) { var department = _repositoryDepart.Get(command.DepartmentId); var employee = new Employee(0, command.FirstName, command.LastName, command.Email, command.DepartmentId, command.BirthDate, command.Active); if (department == null) { AddNotification("Employee", "Não foi encontrado o departamento indicado"); } if (employee.IsValid()) { _repository.Save(employee); } return(employee); }
public void Run() { IExecutable command = null; string line = Console.ReadLine(); while (line != "end") { string[] tokens = line.Split(); switch (tokens[0]) { case "create-company": command = new CreateCompanyCommand(db, tokens[1], tokens[2], tokens[3], decimal.Parse(tokens[4])); break; case "create-employee": string departmentName = null; if (tokens.Length > 5) { departmentName = tokens[5]; } command = new CreateEmployeeCommand(db, tokens[1], tokens[2], tokens[3], tokens[4], departmentName); break; case "create-department": string mainDepartmentName = null; if (tokens.Length > 5) { mainDepartmentName = tokens[5]; } command = new CreateDepartmentCommand(db, tokens[1], tokens[2], tokens[3], tokens[4], mainDepartmentName); break; case "pay-salaries": command = new PaySalariesCommand(tokens[1], db); break; case "show-employees": command = new ShowEmployeesCommand(tokens[1], db); break; } try { Console.Write(command.Execute()); } catch (Exception e) { Console.WriteLine(e.Message); } finally { line = Console.ReadLine(); } } }