Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
        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));
        }