CreateEmployeeRequest GetRequestInfo() { // Get the Json from the POST. string strJson = String.Empty; HttpContext context = HttpContext.Current; context.Request.InputStream.Position = 0; using (StreamReader inputStream = new StreamReader(context.Request.InputStream)) { strJson = inputStream.ReadToEnd(); } // Deserialize the Json. CreateEmployeeRequest req = JsonConvert.DeserializeObject <CreateEmployeeRequest>(strJson); return(req); }
/// <summary> /// Creates new employee /// </summary> /// <param name="employee">Create employee request</param> public WebEmployee CreateEmployee(CreateEmployeeRequest employee) { var dbDepartment = _dbContext.Departments.First(d => d.Id == employee.DepartmentId); if (dbDepartment == null) { throw new NotFoundException($"Department {employee.DepartmentId} does not exist"); } var dbSalaryInfo = _dbContext.Salaries.First(d => d.Id == employee.SalaryId); if (dbSalaryInfo == null) { throw new NotFoundException($"Salary info {employee.DepartmentId} does not exist"); } var dbEmployee = new Employee { FirstName = employee.FirstName, SecondName = employee.SecondName, Address = employee.Address, Department = dbDepartment, DepartmentId = employee.DepartmentId, SalaryInfo = dbSalaryInfo, SalaryInfoId = employee.SalaryId, }; using (var txn = _dbContext.Database.BeginTransaction()) { try { _dbContext.Employees.Add(dbEmployee); _dbContext.SaveChanges(); txn.Commit(); } catch { txn.Rollback(); throw; } } return(dbEmployee.EmployeeToWebEmployee()); }
public IHttpActionResult Create(CreateEmployeeRequest request) { var command = _mapper.Map <CreateEmployeeCommand>(request); _commandSender.Send(command); var locationAggregateID = _locationRepo.GetByID(request.LocationID).AggregateID; var assignCommand = new AssignEmployeeToLocationCommand( locationAggregateID, request.LocationID, request.EmployeeID); _commandSender.Send(assignCommand); return(Ok()); }
public void CreateEmployee() { var request = new CreateEmployeeRequest { Fullname = "TesteUser", PreferedName = "User", Telephone = "07987979", Email = "*****@*****.**", IsLive = true }; MyWebApi .Routes() .ShouldMap("api/employee/createemployee") .WithHttpMethod(HttpMethod.Post) .WithJsonContent(@"{""Fullname"":""TesteUser"",""PreferedName"":""User"", ""Telephone"":""07987979"",""Email"":""*****@*****.**"", ""isLive"":true}") .To <EmployeeController>(c => c.CreateEmployee(request)) .ToInvalidModelState(); }
public async Task <IActionResult> Create([FromBody] CreateEmployeeRequest employeeRequest) { if (employeeRequest != null) { var response = await employeeService.CreateEmployeeAsync(employeeRequest); if (response.Success) { return(Ok(response.EmployeeRecord)); } return(base.BadRequest(new EmployeeResponse { Errors = response.Errors })); } return(base.BadRequest(new EmployeeResponse { Errors = new[] { "Something went wrong" } }));; }
static void Main(string[] args) { Random random = new Random(); var empList = new List <CreateEmployeeRequest>(); var dateOfBirth = DateTime.Now.AddMonths(-1); for (int i = 0; i < 1000000; i++) { var em = new CreateEmployeeRequest { FirstName = "asdf", EmployeeID = 1, DateOfBirth = dateOfBirth }; empList.Add(em); } Stopwatch stopwatch2 = new Stopwatch(); stopwatch2.Start(); FluentValidator(empList); stopwatch2.Stop(); Console.WriteLine("Elapsed: " + stopwatch2.ElapsedMilliseconds); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); MyValidator(empList); stopwatch.Stop(); Console.WriteLine("My Elapsed: " + stopwatch.ElapsedMilliseconds); Console.ReadKey(); }
public async Task <object> Post(CreateEmployeeRequest request) { try { var employee = new Employee { Id = request.Id, Name = request.Name, Department = request.Department, Address = request.Address, City = request.City, Country = request.Country, }; if (string.IsNullOrEmpty(request.Id)) { await _employeeRepository.AddEmployee(employee); } else { await _employeeRepository.UpdateEmployee(request.Id, employee); } return(new EmployeeResponse() { Id = employee.Id, Name = employee.Name, Department = employee.Department, Address = employee.Address, City = employee.City, Country = employee.Country }); } catch (Exception ex) { return(this.ErrorResult(new string[] { ex.Message })); } }
public IActionResult CreateEmployee([FromBody] CreateEmployeeRequest createEmployeeRequest) { var employee = _employeeManager.CreateEmployee(createEmployeeRequest); return(Ok(employee)); }
public async Task <Guid> CreateEmployee([FromBody] CreateEmployeeRequest request) { return(await _employeeService.CreateEmployee(request)); }
public void Post([FromBody] CreateEmployeeRequest request) { _employeeService.CreateEmployee(request); }
public void Save(CreateEmployeeRequest request) { dispatcher.Send(request); }
public async Task NormalEmployee() { var request = new CreateEmployeeRequest() { PersonalIdentificationNumber = "1234567890", UserName = "******", }; var employeeId = await _employeeController.CreateEmployee(request); var customerRequest = new CreateCustomerRequest() { EmployeeId = employeeId, PersonalIdentificationNumber = "customer ssn", UserName = "******", Address = "address" }; var customerId = await _customerController.CreateCustomer(customerRequest); var createInvoiceRequest = new CreateInvoiceRequest() { EmployeeId = employeeId, CustomerId = customerId, PayInAdvance = false, InvoiceItems = new List <InvoiceItemDto>() { new InvoiceItemDto() { Price = 10000.0m, Description = "städning" } }.ToArray(), EndDate = DateTime.Now, StartDate = DateTime.Now, Name = "invoiceName", Vat = 25m, InvoiceDescription = "invoice description" }; var invoiceId = await _invoiceController.CreateInvoice(createInvoiceRequest); var assignment = await _assignmentController.GetAssignment(invoiceId); Assert.Equal(Status.Created, assignment.CurrentStatus); await _invoiceController.SendInvoice(invoiceId); var payment = await _paymentController.GetPayment(invoiceId); Assert.Equal(PaymentState.WaitingForPayment, payment.CurrentState); // simulate payment await _paymentController.SimulateReceivePayment(new ReceivePaymentRequest() { InvoiceId = invoiceId }); payment = await _paymentController.GetPayment(invoiceId); Assert.Equal(PaymentState.PaymentReceived, payment.CurrentState); var payout = await _payoutController.GetPayout(invoiceId); Assert.Equal(5060m, Math.Floor(payout.Amount)); assignment = await _assignmentController.GetAssignment(invoiceId); Assert.Equal(Status.Closed, assignment.CurrentStatus); }
public async Task PaymentDue() { var request = new CreateEmployeeRequest() { PersonalIdentificationNumber = "1234567890", UserName = "******", }; var employeeId = await _employeeController.CreateEmployee(request); var customerRequest = new CreateCustomerRequest() { EmployeeId = employeeId, PersonalIdentificationNumber = "customer ssn", UserName = "******", Address = "address" }; var customerId = await _customerController.CreateCustomer(customerRequest); var createInvoiceRequest = new CreateInvoiceRequest() { EmployeeId = employeeId, CustomerId = customerId, PayInAdvance = false, InvoiceItems = new List <InvoiceItemDto>() { new InvoiceItemDto() { Price = 10000.0m, Description = "städning" } }.ToArray(), EndDate = DateTime.Now, StartDate = DateTime.Now, Name = "invoiceName", Vat = 25m, InvoiceDescription = "invoice description" }; var invoiceId = await _invoiceController.CreateInvoice(createInvoiceRequest); var assignment = await _assignmentController.GetAssignment(invoiceId); Assert.Equal(Status.Created, assignment.CurrentStatus); await _invoiceController.SendInvoice(invoiceId); var payment = await _paymentController.GetPayment(invoiceId); Assert.Equal(PaymentState.WaitingForPayment, payment.CurrentState); await _paymentController.SimulatePaymentDue(new PaymentDueRequest() { InvoiceId = invoiceId }); var invoice = await _invoiceController.GetInvoice(invoiceId); Assert.NotNull(invoice.ReminderSentDate); await _paymentController.SimulatePaymentDebtCollection(invoiceId); await _paymentController.SimulatePaymentPaymentInjuction(invoiceId); await _paymentController.SimulatePaymentDistraint(invoiceId); var payout = await _payoutController.GetPayout(invoiceId); Assert.Null(payout); assignment = await _assignmentController.GetAssignment(invoiceId); Assert.Equal(Status.WaitingForPaymentFromCustomer, assignment.CurrentStatus); }
public async Task <GenericResponse> CreateEmployee([FromBody] CreateEmployeeRequest request) { return(await employeeService.CreateEmployee(request)); }