public async Task <ActionResult> Create(EmployeeCreateOrUpdate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.ValidationState)); } Employee employee = new Employee { Id = Guid.NewGuid(), Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, }; try { await _employeeRepository.CreateAsync(employee); return(Ok($"Created employee with Id = {employee.Id}")); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating data")); } }
public async Task <ActionResult> Update(Guid id, EmployeeCreateOrUpdate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.ValidationState)); } Employee employee = await _employeeRepository.GetByIdAsync(id); if (employee is null) { return(NotFound($"Employee with Id = {id} not found")); } employee.Email = model.Email; employee.FirstName = model.FirstName; employee.LastName = model.LastName; try { await _employeeRepository.UpdateAsync(employee); return(Ok($"Updated employee with Id = {employee.Id}")); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error updating data")); } }