public ResponseModel <bool> Post([FromBody] EmployeeInputDto employee) { var result = new ResponseModel <bool> { Status = ResponseStatus.Fail }; if (!ModelState.IsValid) { var errors = string.Join(" ", ModelState.Values.Select(x => string.Join(" ", x.Errors.Select(e => e.ErrorMessage)))); result.Message = errors; result.Status = ResponseStatus.Fail; return(result); } return(result); }
/// <summary> /// Add employee. /// </summary> /// <param name="employee"></param> /// <returns></returns> public async Task <EmployeeOutputDto> Add(EmployeeInputDto employee) { if (employee == null) { throw new ArgumentNullException("Employee is null"); } if (string.IsNullOrEmpty(employee.Firstname) || string.IsNullOrEmpty(employee.Lastname) || string.IsNullOrEmpty(employee.Tin)) { throw new Exception("Parameter has null or empty values"); } var employeeEntity = _mapper.Map <Employee>(employee); employeeEntity.Id = new Guid(); await _employeeRepository.Add(employeeEntity); return(_mapper.Map <EmployeeOutputDto>(employeeEntity)); }
public async Task <IActionResult> Create(EmployeeInputDto employee) { await _employeeService.Add(employee); return(RedirectToAction("Get")); }