public bool Create(EmployeeView model) { try { EmployeeValidator validator = new EmployeeValidator(model); if (!validator.IsValid()) { throw new Exception(validator.GetErrors()); } return(this.Repository.Create(model)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> Create(EmployeeEditModel newEmployee) { if (!ModelState.IsValid) { return(BadRequest()); } var errors = _employeeValidator.GetErrors(newEmployee); if (errors.Any()) { return(BadRequest(string.Join(" ", errors))); } var newEmployeeId = await _employeeCrud.Create(newEmployee); return(Ok(newEmployeeId)); }