public async Task <ActionResult> Create(EmployeeDto employeeDto) { if (string.IsNullOrEmpty(employeeDto.FirstName) || string.IsNullOrEmpty(employeeDto.LastName) || string.IsNullOrEmpty(employeeDto.Salary) || string.IsNullOrEmpty(employeeDto.PositionId) || !Guid.TryParse(employeeDto.PositionId, out var positionId) || employeeDto.HireDate == null) { return(StatusCode(StatusCodes.Status422UnprocessableEntity)); } var position = await positionRepository.GetAsync(positionId); if (position == null) { return(StatusCode(StatusCodes.Status422UnprocessableEntity, $"Position with id {employeeDto.PositionId} was not found")); } var employee = new Employee(employeeDto.FirstName, employeeDto.LastName, employeeDto.Salary, employeeDto.HireDate.Value); employee.ChangePosition(position, employeeDto.HireDate.Value); if (employeeDto.DismissalDate.HasValue) { employee.DismissalEmployee(employeeDto.DismissalDate.Value); } await employeeRepository.InsertAsync(employee); return(CreatedAtAction( nameof(Get), new { id = employee.Id.ToString() }, EmployeeSummary.FromDomain(employee))); }
/*******************************************************************************************************************\ * * \*******************************************************************************************************************/ private void mk_report(DateTime start_date, System.Data.DataTable dt) { List <Dictionary <string, string[]> > data; List <Dictionary <string, int> > summary; EmployeeSummary es = new EmployeeSummary(start_date, dt); data = es.EmpData; summary = es.Summary; //excel_report(data, summary); RptSummary rpt = new RptSummary(); rpt.excel_report(data, summary); }
public async Task <IActionResult> GetAll( [FromQuery] string filter = null, [FromQuery] int?page = 1, [FromQuery] int?pageSize = 10, CancellationToken ct = default) { if (pageSize > ApiLimits.MaxResultsPerCall) { return(new ObjectResult($"No more than {ApiLimits.MaxResultsPerCall} results per page") { StatusCode = (int)HttpStatusCode.ExpectationFailed }); } (IReadOnlyEmployee[] Employees, int Total)filterResult = await _employeesRepository.GetAllPaging(filter, page, pageSize, ct); return(Ok(new GetAllEmployeesResult { Total = filterResult.Total, Employees = filterResult.Employees.Select(x => EmployeeSummary.Load(x, _getUtcNow)) })); }
public async Task <IEnumerable <EmployeeSummary> > Get() { var employees = await employeeRepository.GetAsync(); return(employees.Select(domain => EmployeeSummary.FromDomain(domain))); }