public async Task Update(int employeeId, EmployeeManipulationDto employee) { var employeeEntity = await _repositoryManager.EmployeeRepository.GetEmployeeAsync(employeeId, trackChanges : true); _mapper.Map(employee, employeeEntity); await _repositoryManager.SaveAsync(); }
public async Task <EmployeeReadDto> Create(int userId, EmployeeManipulationDto employee) { var employeeEntity = _mapper.Map <Employee>(employee); var emp = _repositoryManager.EmployeeRepository.CreateEmployee(userId, employeeEntity); await _repositoryManager.SaveAsync(); return(_mapper.Map <EmployeeReadDto>(emp)); }
public async Task <IActionResult> UpdateEmployee(int employeeId, [FromBody] EmployeeManipulationDto employee) { try { await _manager.EmployeeServices.Update(employeeId, employee); return(NoContent()); } catch (BadHttpRequestException) { return(BadRequest()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Error", Message = "Internal server error" })); } }
public async Task <IActionResult> RegisterEmployee(EmployeeManipulationDto employee) { var IsExisted = await _manager.UserServices.UserExist(employee.Email); if (IsExisted != null) { return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Error", Message = "Email existed before try another one" })); } else { try { var user = new AppUser { Name = employee.Name, Email = employee.Email, CreatedDate = employee.CreatedDate, RoleId = employee.RoleId, Password = employee.Password }; await _manager.UserServices.RegisterUser(user); var emp = await _manager.EmployeeServices.Create(user.Id, employee); return(Created("Employee created successfully", emp)); } catch (BadHttpRequestException) { return(BadRequest()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Error", Message = ex.Message })); } } }