public DatabaseCode Insert(User user) { using (IDbConnection con = CreateConnection()) { try { bool exists = Exist(user.username); if (!exists) { user.password = cryptoHelper.HashPassword(user.password); con.Insert <User>(user); return(DatabaseCode.Inserted); } return(DatabaseCode.Exists); } catch (System.Exception ex) { logger.LogError(ex, "Failed to insert new user", new { user = JsonConvert.SerializeObject(user) }); return(DatabaseCode.Error); } } }