public async Task <BusinessResult <UserDTO> > CreateAsync(UserDTO entity) { try { if (!ValidatePassword(entity.UserPass)) { throw new UserException(General.InvalidPassword); } entity.CreationDate = DatetimeHelper.GetCurrentColombianTime(); var resultOperation = await _iuserModel.CreateAsync(entity); return(BusinessResult <UserDTO> .Success(resultOperation, General.OperationSucsess)); } catch (UserException user) { return(BusinessResult <UserDTO> .Issue(null, user.Message, user)); } catch (GenericADOException ex) { var sql = ex.InnerException as SqlException; if (sql != null && sql.Number == 2627) { // Here's where to handle the unique constraint violation return(BusinessResult <UserDTO> .Issue(null, General.UniqueUserName, sql)); } else { return(BusinessResult <UserDTO> .Issue(null, General.OperationIssue, sql)); } } catch (Exception ex) { return(BusinessResult <UserDTO> .Issue(null, General.OperationIssue, ex)); } }